470,862 Members | 1,734 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,862 developers. It's quick & easy.

can't seem to figure out...

<inbox>
<email>
<to>John Doe</to>
<from>Jane Doe</from>
<subject>This is the subject</subject>
<paragraph>P1</paragraph>
<paragraph>P2</paragraph>
<paragraph>P3</paragraph>
<paragraph>P4</paragraph>
</email>
</inbox>

I'm trying to get the text within the multiple <paragraph> tags through
XSLT. If I have the following XSLT stylesheet:

<xsl:template match="/">
<html>
<body>
<p>To: <xsl:value-of select="to"/></p>
<p>From: <xsl:value-of select="from"/></p>
<p>Subject: <xsl:value-of select="subject"/></p>
</body>
</html>
</xsl:template>

If I want to cycle through the four paragraphs in the above, how would
I do that? I was thinking of using <xsl:for-each> but couldn't figure
out how to get the text.

Thanks...

Apr 10 '06 #1
1 1072
Your thought about xsl:for-each is one solution:
<xsl:for-each select="paragraph">
<xsl:value-of select="."/>
</xsl:for-each>

A more idiomatic solution would be to write a template for each of the
element types and let apply-template recursion take care of this iteration.

<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="to">
<p>To: <xsl:value-of select="."/></p>
</xsl:template>
<xsl:template match="from">
<p>From: <xsl:value-of select="."/></p>
</xsl:template>
<xsl:template match="subject">
<p>Subject: <xsl:value-of select="."/></p>
</xsl:template>
<xsl:template match="paragraph">
<p><xsl:value-of select="."/></p>
</xsl:template>


--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Apr 10 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Scott Wilkins | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.