user2043927
user2043927

Reputation:

for-each doesn't work for my xslt

I have a problem I couldn't solve despite extensive searching... This is a part from an XML.

<contributors>
<authors>
<author>Willett, C G</author>
<author>Tepper, J E</author>
<author>Kaufman, D S</author>
<author>Shellito, P C</author>
<author>Eliseo, R</author>
<author>Convery, K</author>
<author>Wood, W C</author>
</authors>
</contributors>

I tried to import all authors into a Filemaker cell by using this xsl (excerpt)

<FIELD EMPTYOK="YES" MAXREPEAT="15" NAME="Author" TYPE="TEXT"/>
    <COL>
<DATA>
<xsl:for-each select="contributors/authors">
<xsl:value-of select="author">
</xsl:value-of>
</xsl:for-each>
</DATA>
</COL>

Unfortunately only the first name is imported. Why? What's missing?

Would be glad if someone could help me...

Cheers

Upvotes: 0

Views: 890

Answers (2)

Ian Roberts
Ian Roberts

Reputation: 122394

<FIELD EMPTYOK="YES" MAXREPEAT="15" NAME="Author" TYPE="TEXT"/>
  <COL>
    <DATA>
      <xsl:for-each select="contributors/authors/author">
        <xsl:value-of select="."/>
        <xsl:if test="position() &lt; last()">; </xsl:if>
      </xsl:for-each>
    </DATA>
  </COL>

This would produce a semicolon-separated list of all the author values. The <xsl:if> is there to avoid adding a trailing semicolon after the last author name.

Upvotes: 0

JLRishe
JLRishe

Reputation: 101738

You need to iterate through the authors, not through authors, because there's only one authors, but many authors:

<xsl:for-each select="contributors/authors/author">
    <xsl:value-of select="concat(., ' ')" />
</xsl:for-each>

Upvotes: 3

Related Questions