Test on child elements - alternative?

Discussion in 'XML' started by Phil Jenkins, Jun 27, 2006.

  1. Phil Jenkins

    Phil Jenkins Guest

    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
    Phil Jenkins, Jun 27, 2006
    #1
    1. Advertising

  2. Phil Jenkins

    William Guest

    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
    William, Jun 27, 2006
    #2
    1. Advertising

  3. Phil Jenkins

    Phil Jenkins Guest

    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
    Phil Jenkins, Jun 27, 2006
    #3
  4. Phil Jenkins

    Phil Jenkins Guest

    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()
    Phil Jenkins, Jun 27, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bhchng
    Replies:
    0
    Views:
    643
    bhchng
    Jan 13, 2004
  2. www.raph.nl
    Replies:
    0
    Views:
    542
    www.raph.nl
    Oct 3, 2003
  3. Gerald Aichholzer
    Replies:
    2
    Views:
    2,482
    Gerald Aichholzer
    Jun 27, 2006
  4. Jeff Rodriguez
    Replies:
    23
    Views:
    1,093
    David Schwartz
    Dec 9, 2003
  5. Skybuck Flying

    Call oddities: &Test() vs &Test vs Test

    Skybuck Flying, Oct 4, 2009, in forum: C Programming
    Replies:
    1
    Views:
    683
    Skybuck Flying
    Oct 4, 2009
Loading...

Share This Page