Re: [xsl] testing for position of an element and displaying it accordingly

Subject: Re: [xsl] testing for position of an element and displaying it accordingly
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Fri, 19 Jan 2007 16:47:16 +0100
Hi 'ms',

You posted a test template that is not valid XML. But even after correcting the typos, the output of your XSLT is not even close to what you say that output is. Have you tried your own XSLT that you propose here? You seem to be outputting HTML (or parts of it), but there is no bit of HTML in the description of your output, which is purely text.

Supposing your output method is HTML, this is what your current template gives:
testtest2test3<ol>
<li type="1">
test
test2
test test
test3
</li>
</ol>



And that is *very far from* what you think it does.


What parser do you use for transformation? Can you paste your code, because maybe something went wrong while typing it over?

also, a few notes:
1. switching modes is not necessary for this kind of problem
2. the xsl:if is entirely redundant, the xsl:apply-templates takes care of that for you. It looks like a procedural instruction to me, as if you can control the program flow. But in XSLT you can't (this is a common misunderstanding)
3. you apply the templates twice. Is that on purpose?


Please clarify what you want, and give the exact input you use and the exact output you require (if HTML, show us HTML, if text, show us text). Also, check what you have in your project and test the input/output just before pasting it here, so we can be sure of talking about the right problem.

Cheers,
-- Abel Braaksma


ms wrote:
<xsl:template match="r1">
<!-- The mode is applid for any <a> element that
appears before the <b> element in the xml-->
<xsl:if test child::a>
<xsl:apply-templates select="a" mode="test"/>
</xsl:if>
<ol>
<li type="1">
<xls:applly-templates/>
</li>
</ol>
</xsl:template>

So, r1 is formatted with number 1.

<xsl:template match="a" mode="test">
<xsl:apply-templates mode="test"/>
</xsl:template>

Current Thread