Stuart A Yeates
Usenet Archive
- Joined
- Jun 21, 2002
- Messages
- 13
- Reaction score
- 0
I'm trying to write a template that matches "*" but which has an if clause which if only executed once per type of element seen (where all elements of a type have the same name and namespace). The test in the example below doesn't work, but it seems that there must be some relatively simple text i'm overlooking.
<!--
- process an element
-->
<xsl:template match="*">
<xsl:copy>
<xsl:if test="last=position">
<xsl:text>
i occur once for each type of element. this time it's for:
</xsl:text>
<xsl:value-of select="."/>
</xsl:if>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
If my input is:
<a>
<b> <d/><d/> </b>
<c> <d/><b/> </c>
</a>
I want instantiate the body of my if once for <a>, once for <b>, once for <c> and once for <e>. It doesn't really bother me what order they happen it.
I suspect that what I need is a recursive template that finds determines whether the current element occupies some special place (first or last), but i'm not sure how to write it.
stuart
<!--
- process an element
-->
<xsl:template match="*">
<xsl:copy>
<xsl:if test="last=position">
<xsl:text>
i occur once for each type of element. this time it's for:
</xsl:text>
<xsl:value-of select="."/>
</xsl:if>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
If my input is:
<a>
<b> <d/><d/> </b>
<c> <d/><b/> </c>
</a>
I want instantiate the body of my if once for <a>, once for <b>, once for <c> and once for <e>. It doesn't really bother me what order they happen it.
I suspect that what I need is a recursive template that finds determines whether the current element occupies some special place (first or last), but i'm not sure how to write it.
stuart