Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Test on child elements - alternative?

Reply
Thread Tools

Test on child elements - alternative?

 
 
Phil Jenkins
Guest
Posts: n/a
 
      06-27-2006
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

 
Reply With Quote
 
 
 
 
William
Guest
Posts: n/a
 
      06-27-2006
Replace ".//" with ".//*" and see if that helps.

\/\//\ Wim

Phil Jenkins wrote:
> 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


 
Reply With Quote
 
 
 
 
Phil Jenkins
Guest
Posts: n/a
 
      06-27-2006
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

 
Reply With Quote
 
Phil Jenkins
Guest
Posts: n/a
 
      06-27-2006
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()

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT: iterating all child elements and accessing homonymous childrenin sibling elements Gerald Aichholzer XML 2 06-27-2006 03:46 PM
EJB: How to delete child entries from a parent-child CMR one-to-many relationship? davout Java 0 04-18-2004 07:02 PM
[HELP] Why the child window reopen a new child window ? bhchng ASP .Net 0 01-13-2004 07:17 AM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments