[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Looping

Subject: Looping
From: Nathan Tallman <ntallman@xxxxxxxxx>
Date: Wed, 11 Apr 2012 16:01:15 -0400
 Looping
Hi XSL list,

I'm a fairly new XSL user and am still figuring things out. Right now
I'm having trouble looping through repeated elements.

Here's my source XML snippet:

<ead>
...
    <archdesc>
    ...
        <did>
        ...
            <langmaterial encodinganalog="546">Collection material in
                <language encodinganalog="041$a"
langcode="eng">English</language>,
                <language encodinganalog="041$a"
langcode="yid">Yiddish</language>, and
                <language encodinganalog="041$a"
langcode="rus">Russian</language>.
            </langmaterial>
			
Here's my XSL snippet:

<xsl:if test="/ead/archdesc/did/langmaterial">
    <xsl:for-each select="/ead/archdesc/did/langmaterial/language[1]">
        <marc:datafield tag="041" ind1=" " ind2=" ">
            <marc:subfield code="a">
                <xsl:value-of
select="normalize-space(/ead/archdesc/did/langmaterial/language[1]/@langcode)"
/>
            </marc:subfield>
        </marc:datafield>
    </xsl:for-each>

    <xsl:for-each select="/ead/archdesc/did/langmaterial/language[2]">
        <marc:datafield tag="041" ind1=" " ind2=" ">
            <marc:subfield code="a">
                <xsl:value-of
select="normalize-space(/ead/archdesc/did/langmaterial/language[2]/@langcode)"
/>
            </marc:subfield>
        </marc:datafield>
    </xsl:for-each>

    <xsl:for-each select="/ead/archdesc/did/langmaterial/language[3]">
        <marc:datafield tag="041" ind1=" " ind2=" ">
            <marc:subfield code="a">
                <xsl:value-of
select="normalize-space(/ead/archdesc/did/langmaterial/language[3]/@langcode)"
/>
            </marc:subfield>
        </marc:datafield>
    </xsl:for-each>			
</xsl:if>

Right now, this achieves what I want. Each langcode is represented by
an individual MARC 041 field. But, as you can see, I have hard coded
each node sequentially. In my XSL, I repeat this ten times, in
anticipation of more langcodes. Is there an easy way to code the
output I want, and then have this loop until it has covered each
instance of <language>?

I've tried this:
			   <xsl:if test="/ead/archdesc/did/langmaterial">
			      <xsl:for-each select="/ead/archdesc/did/langmaterial/language">
			         <marc:datafield tag="041" ind1=" " ind2=" ">
			            <marc:subfield code="a">
			               <xsl:value-of
select="normalize-space(/ead/archdesc/did/langmaterial/language/@langcode)"
/>
			            </marc:subfield>
			         </marc:datafield>
			      </xsl:for-each>
			   </xsl:if>
But it only repeats the first @langcode three times, instead of having
three distinct outputs.

Many thanks!

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.