Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

processing child nodes in xsl

Status
Not open for further replies.

lowbk

Technical User
Nov 26, 2001
162
SG
hi guys, need some advice on processing child nodes
suppose i've a xml that looks like the below
....

<section>
<caption>section name</caption>
<content>some data</content>
</section>

<section>
<caption>section name</caption>
<content>
<media>....</media>
</content>
</section>

....

to transform the section, i have the following xsl

<xsl:template match=&quot;caption|content&quot;>
<xsl:for-each select=&quot;child::*&quot; >
<xsl:if test=&quot;self::&quot;>
<xsl:value-of select=&quot;.&quot; />
</xsl:if>

<xsl:if test=&quot;self::media&quot;>
<xsl:call-template name=&quot;media&quot; />
</xsl:if>
</xsl:for-each>
</xsl:template>


i'm having problems with the bold line. it is meant to display the caption or content if there is no child node to it..but dunno what to put in.

can anyone advise?
 
Try something like the following...

<xsl:template match=&quot;caption|content&quot;>

<xsl:if test=&quot;not(child::node())&quot;>
<xsl:value-of select=&quot;.&quot; />
</xsl:if>

<xsl:for-each select=&quot;child::*&quot; >
<xsl:if test=&quot;self::media&quot;>
<xsl:call-template name=&quot;media&quot; />
</xsl:if>
</xsl:for-each>
</xsl:template>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top