Index: trunk/gsdl/etc/dc2marc.xsl
===================================================================
--- trunk/gsdl/etc/dc2marc.xsl	(revision 13224)
+++ trunk/gsdl/etc/dc2marc.xsl	(revision 13342)
@@ -8,21 +8,5 @@
   <xsl:param name="mapping" />	
 
-  <xsl:variable name="lang" >
-       	<xsl:choose>      
-           <xsl:when test="/MARCXML/MetadataList/Metadata[@name='dc.Language']">
-                <xsl:value-of select="/MARCXML/MetadataList/Metadata[@name='dc.Language']"/>                    
-            </xsl:when>   
-            <xsl:when test="/MARCXML/MetadataList/Metadata[@name='Language']">
-                  <xsl:value-of select="/MARCXML/MetadataList/Metadata[@name='Language']"/>
-            </xsl:when> 
-             <xsl:otherwise>
-                 <xsl:value-of select="en"/>	
-             </xsl:otherwise>
-           </xsl:choose>   
-   </xsl:variable>	
-  <xsl:variable name="item" select="$mapping/stopwords[@lang=$lang]/item"/>
-  
-
- <xsl:template match="/">
+  <xsl:template match="/">
      <collection>
            <xsl:apply-templates select="/MARCXML/MetadataList"/>
@@ -31,4 +15,24 @@
  
   <xsl:template match="MetadataList">
+       <xsl:variable name="lang" >
+       	<xsl:choose>      
+           <xsl:when test="Metadata[@name='dc.Language']">
+                <xsl:value-of select="Metadata[@name='dc.Language']"/>                    
+            </xsl:when>            
+            <!-- comment out this if you want to test dls.Language as well
+             <xsl:when test="Metadata[@name='dls.Language']">
+                <xsl:value-of select="Metadata[@name='dls.Language']"/>                    
+             </xsl:when>
+            -->
+            <xsl:when test="Metadata[@name='Language']">
+                  <xsl:value-of select="Metadata[@name='Language']"/>
+            </xsl:when>           
+           <!-- the defualt language is english --> 
+            <xsl:otherwise>
+                 <xsl:value-of select="en"/>	
+             </xsl:otherwise>
+           </xsl:choose>   
+       </xsl:variable>	
+      <xsl:variable name="item" select="$mapping/stopwords[@lang=$lang]/item"/>
       <record>
 	  <xsl:apply-templates select="$mapping/leader">
@@ -37,5 +41,6 @@
           <xsl:apply-templates select="$mapping/controlfield[@required='true']" /> 
       	  <xsl:apply-templates select="$mapping/MarcField" >
-	      <xsl:with-param name="source" select="." />   
+	      <xsl:with-param name="source" select="." /> 
+              <xsl:with-param name="item" select="$item" />   
 	  </xsl:apply-templates>                       
       </record>   
@@ -107,4 +112,5 @@
   <xsl:template match="MarcField">
    <xsl:param  name="source" />  
+   <xsl:param  name="item" /> 
    <xsl:variable name="this" select="."/> 
    <xsl:choose>
@@ -114,5 +120,6 @@
          <xsl:apply-templates select="$this/subfield[1]" mode="testing"> 
                 <xsl:with-param name="pos" select="position()"/> 
-	        <xsl:with-param name="source" select="$source"/> 
+	        <xsl:with-param name="source" select="$source"/>
+                <xsl:with-param name="item" select="$item"/> 
             </xsl:apply-templates>
         </xsl:for-each>
@@ -123,5 +130,6 @@
            <xsl:apply-templates select="$this/subfield[1]" mode="testing"> 
                <xsl:with-param name="pos" select="position()+1"/> 
-	       <xsl:with-param name="source" select="$source"/>  
+	       <xsl:with-param name="source" select="$source"/>
+               <xsl:with-param name="item" select="$item"/>  
             </xsl:apply-templates>
         </xsl:for-each>
@@ -131,4 +139,5 @@
            <xsl:with-param name="pos" select="'0'"/> 
 	   <xsl:with-param name="source" select="$source"/> 
+           <xsl:with-param name="item" select="$item"/>  
          </xsl:apply-templates>
        </xsl:otherwise> 
@@ -139,4 +148,5 @@
      <xsl:param name="pos"/>
      <xsl:param  name="source" /> 
+     <xsl:param  name="item" />
      <xsl:variable name="meta" select="@meta"/>
      <xsl:choose>     
@@ -145,4 +155,5 @@
              <xsl:apply-templates select="../@*" mode="mapping-attribute">
                <xsl:with-param name="source" select="$source"/>
+                <xsl:with-param name="item" select="$item"/>
              </xsl:apply-templates>                                      
              <xsl:apply-templates select="../subfield[not(@nonfiling)]" >                       
@@ -153,5 +164,8 @@
        </xsl:when>
        <xsl:otherwise>
-             <xsl:apply-templates select="following-sibling::*[1]" mode="testing" >              	         <xsl:with-param name="source" select="$source"/>
+             <xsl:apply-templates select="following-sibling::*[1]" mode="testing" >
+                    <xsl:with-param name="pos" select="$pos"/> 
+            	    <xsl:with-param name="source" select="$source"/>
+                    <xsl:with-param name="item" select="$item"/>
              </xsl:apply-templates> 
          </xsl:otherwise>
@@ -161,5 +175,6 @@
 
   <xsl:template match="@*" mode="mapping-attribute" >
-     <xsl:param name="source" /> 	
+     <xsl:param name="source" />
+     <xsl:param name="item" /> 	
      <xsl:variable name="name" select="name()"/>
      <xsl:variable name="value" select="."/>
@@ -192,4 +207,5 @@
      <xsl:param name="subfield" />
      <xsl:param name="source" />
+
   <xsl:variable name="itemname" select="@name"/>
   <xsl:variable name="lowercasecontent" select="xsltutil:toLowerCase($content)"/>		
@@ -197,5 +213,5 @@
            <xsl:when test="starts-with($lowercasecontent,$itemname) or count(following-sibling::*)=0">
                <xsl:choose>
-                 <xsl:when test="count(following-sibling::*) !=0 ">              
+                 <xsl:when test="starts-with($lowercasecontent,$itemname)" >              
                       <xsl:call-template name="addAttribute" >
                          <xsl:with-param name="name" select="$name"/>
@@ -251,5 +267,5 @@
       <xsl:choose>
         <xsl:when test="@nonfiling='true'">
-          <subfield code="{@code}"><xsl:value-of select="substring($content,$length+1)"/><xsl:value-of select="@punc"/></subfield>
+          <subfield code="{@code}"><xsl:value-of select="$content"/><xsl:value-of select="@punc"/></subfield>
         </xsl:when>
         <xsl:when test="$pos >0">
@@ -268,3 +284,2 @@
   
 </xsl:stylesheet>
-
