[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Cho, Minho wrote:
That's what template matching is all about. For-loops are a usage from imperative languages, whereas XSLT more like a functional one. Using a template match will 'call' that template automagically each time the processor encounters a node that fits the specification in the match-attribute.
Thus, instead of using for-each, you could best use the example from Richard. It will save you from a lot of xsl:if and xsl:choose branches (also procedural heritage)
This will select ALL infoObjects, at any level, however deep and is an expensive operation. Better do it so:
<xsl:apply-templates select="infoObject/infoObjectDetail[@title='Description']" />
<xsl:template match="infoObjectDetail">
<tr> <td> <xsl:value-of select="."/>
<xsl:text> </xsl:text>
</td>
</tr>
</xsl:template>
Or like this, if you have more of this type of matches, you can specify it more precisely at template level:
<tr> <td> <xsl:apply-templates select="infoObject/infoObjectDetail" />
</td>
</tr>
Of course, if you insist, you can always stick to the for-each loop.
Re: [xsl] XSL and XML Help
Subject: Re: [xsl] XSL and XML Help From: Abel Braaksma <abel.online@xxxxxxxxx> Date: Fri, 13 Oct 2006 15:29:00 +0200 |
Cho, Minho wrote:
I do need the for loop because my xml file has more then one set of infobject.
That's what template matching is all about. For-loops are a usage from imperative languages, whereas XSLT more like a functional one. Using a template match will 'call' that template automagically each time the processor encounters a node that fits the specification in the match-attribute.
Thus, instead of using for-each, you could best use the example from Richard. It will save you from a lot of xsl:if and xsl:choose branches (also procedural heritage)
I GOT IT !! :-) <xsl:for-each select="//infoObject">
<tr>
<td> <xsl:value-of select="infoObjectDetail[@title ='Description']"/>
<xsl:text> </xsl:text>
</td>
</tr>
</xsl:for-each>
This will select ALL infoObjects, at any level, however deep and is an expensive operation. Better do it so:
<xsl:apply-templates select="infoObject/infoObjectDetail[@title='Description']" />
<xsl:template match="infoObjectDetail">
<tr> <td> <xsl:value-of select="."/>
<xsl:text> </xsl:text>
</td>
</tr>
</xsl:template>
Or like this, if you have more of this type of matches, you can specify it more precisely at template level:
<tr> <td> <xsl:apply-templates select="infoObject/infoObjectDetail" />
</td>
</tr>
<xsl:template match="infoObjectDetail[@title='Description]"> <xsl:value-of select="."/> <xsl:text> </xsl:text> </xsl:template>
<xsl:template match="infoObjectDetail[@title!='Description]"> NO DESCRIPTOIN FOUND! </xsl:template>
Of course, if you insist, you can always stick to the for-each loop.
Cheers -- Abel
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] XSL and XML Help, Cho, Minho | Thread | RE: [xsl] XSL and XML Help, Wendell Piez |
[xsl] Xsl:if to determine if any no, David Steketee | Date | RE: [xsl] short and long empty xml , Michael Kay |
Month |