Test on child elements - alternative?

P

Phil Jenkins

Hello there

I've inherited some code, which looks like this:

<!-- recreate the element (with its namespace) -->
<xsl:element name="{local-name()}" namespace="{namespace-uri()}">

<!-- if it has children... -->
<xsl:if test=".//">
<!-- process the children -->
<xsl:apply-templates/>
</xsl:if>
<!-- if it does not have children... -->
<xsl:if test="not(.//)">
<!-- recreate its value -->
<xsl:value-of select="."/>
</xsl:if>
</xsl:element>

Which seems to be a long winded <xsl:copy of> method - but the
important part is that the test for children -> ".//" no longer works
with a newer version of xerces - i'm getting an error along the lines
of "a location step was expected after the //".

So the question is - is there another more correct way of testing for
children right down the node tree, i'm sure there is but i'm stumped
with my limited xslt experience.

Thanks in advance
 
P

Phil Jenkins

Hi Wim

Thanks for that - the error has stopped, but the template match doesn't
exhibit the same behaviour - anything that isn't a child element (i.e
text) is being replicated twice.

<element>Text</element> would come out as TextText.

Thanks for your help so far
 
P

Phil Jenkins

For anyone interested - the error was due to upgrading from Xalan 2.3
to 2.7, where the XPath '//' statement has been replaced with the more
correct /descendant-or-self::node()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top