XSLT: nodes in variables

Discussion in 'XML' started by Johannes Lebek, Aug 15, 2003.

  1. Hi there,

    somehow, I cannot access nodes that are stored in a variable. I'm using
    Xalan 2.5.1 and the following commands:

    ================ BEGIN ====================

    <xsl:variable name="referenced-node" select="//a[@att1 = current()/@att2]"/>

    <xsl:variable name="attribute-source">
    <xsl:choose>
    <xsl:when test="$referenced-node">
    <xsl:copy-of select="$referenced-node"/>
    </xsl:when>
    <xsl:eek:therwise>
    <xsl:copy-of select="."/>
    </xsl:eek:therwise>
    </xsl:choose>
    </xsl:variable>

    <!-- line 556 follows -->
    <!-- this is where the error occurs -->
    <xsl:value-of select="$attribute-source/@att3"/>

    ================= END =====================

    I cannot access $attribute-source. If the node or its attribute 'att3'
    could not be found, nothing would be written. But even then no
    ClassCastException should be thrown.
    Is this problem caused by the <xsl:copy-of> statements? My understand is
    that I can store the nodes in variable $attribute-source using
    <xsl:copy-of>. <xsl:value-of> would not help in this case, because I
    need the node and not its text value.

    If I run Xalan, it tells me:

    ================ BEGIN ====================
    ; SystemID: file:///path/../../stylesheet.xsl; Line#: 556; Column#: 59
    javax.xml.transform.TransformerException: java.lang.ClassCastException
    at
    org.apache.xalan.templates.ElemValueOf.execute(ElemValueOf.java:330)
    at
    org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:425)
    at
    org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:215)
    at
    org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:425)
    at
    org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:215)
    at
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java(Compiled
    Code))
    at org.apache.xalan.templates.ElemIf.execute(ElemIf.java:203)
    at
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2318)
    at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:153)
    at
    org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:425)
    at
    org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:215)
    at
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2318)
    at
    org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:699)
    at
    org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:425)
    at
    org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:215)
    at
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2318)
    at
    org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2185)
    at
    org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1263)
    at
    org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:671)
    at
    org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1179)
    at
    org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1157)
    at org.apache.xalan.xslt.Process.main(Process.java:1025)
    ---------
    java.lang.ClassCastException
    at
    org.apache.xpath.axes.FilterExprIteratorSimple.executeFilterExpr(FilterExprIteratorSimple.java(Compiled
    Code))
    at
    org.apache.xpath.axes.FilterExprWalker.setRoot(FilterExprWalker.java(Compiled
    Code))
    at
    org.apache.xpath.axes.WalkingIterator.setRoot(WalkingIterator.java(Compiled
    Code))
    at
    org.apache.xpath.axes.LocPathIterator.executeCharsToContentHandler(LocPathIterator.java:276)
    at
    org.apache.xalan.templates.ElemValueOf.execute(ElemValueOf.java:311)
    at
    org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:425)
    at
    org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:215)
    at
    org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:425)
    at
    org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:215)
    at
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java(Compiled
    Code))
    at org.apache.xalan.templates.ElemIf.execute(ElemIf.java:203)
    at
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2318)
    at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:153)
    at
    org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:425)
    at
    org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:215)
    at
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2318)
    at
    org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:699)
    at
    org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:425)
    at
    org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:215)
    at
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2318)
    at
    org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2185)
    at
    org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1263)
    at
    org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:671)
    at
    org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1179)
    at
    org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1157)
    at org.apache.xalan.xslt.Process.main(Process.java:1025)

    ================= END =====================

    Any idea, how to access the node stored in $attribute-source?
    Thanks in advance,

    Johannes
     
    Johannes Lebek, Aug 15, 2003
    #1
    1. Advertising

  2. Re: nodes in variables

    Thanks, Marrow, although I found a solution meanwhile, I have to admit
    your's it much smarter!

    Johannes



    Marrow wrote:

    > Hi Johannes,
    >
    > Try something like this code...
    >
    > <xsl:variable name="referenced-node" select="//a[@att1 =
    > current()/@att2]"/>
    > <xsl:variable name="attribute-source" select="$referenced-node |
    > (.)[not($referenced-node)]"/>
    >
    > Hope this helps
    > Marrow
    > http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
    > http://www.topxml.com/Xselerator
    >
    >
    > "Johannes Lebek" <> wrote in message
    > news:bhi9gh$pbe$...
    >
    >>Hi there,
    >>
    >>somehow, I cannot access nodes that are stored in a variable. I'm using
    >>Xalan 2.5.1 and the following commands:
    >>
    >>================ BEGIN ====================
    >>
    >><xsl:variable name="referenced-node" select="//a[@att1 =

    >
    > current()/@att2]"/>
    >
    >><xsl:variable name="attribute-source">
    >> <xsl:choose>
    >> <xsl:when test="$referenced-node">
    >> <xsl:copy-of select="$referenced-node"/>
    >> </xsl:when>
    >> <xsl:eek:therwise>
    >> <xsl:copy-of select="."/>
    >> </xsl:eek:therwise>
    >> </xsl:choose>
    >></xsl:variable>
    >>
    >><!-- line 556 follows -->
    >><!-- this is where the error occurs -->
    >><xsl:value-of select="$attribute-source/@att3"/>
    >>
    >>================= END =====================
    >>
    >>I cannot access $attribute-source. If the node or its attribute 'att3'
    >>could not be found, nothing would be written. But even then no
    >>ClassCastException should be thrown.
    >>Is this problem caused by the <xsl:copy-of> statements? My understand is
    >>that I can store the nodes in variable $attribute-source using
    >><xsl:copy-of>. <xsl:value-of> would not help in this case, because I
    >>need the node and not its text value.
    >>
    >>If I run Xalan, it tells me:
    >>
    >>================ BEGIN ====================
    >>; SystemID: file:///path/../../stylesheet.xsl; Line#: 556; Column#: 59
    >>javax.xml.transform.TransformerException: java.lang.ClassCastException
    >> at
    >>org.apache.xalan.templates.ElemValueOf.execute(ElemValueOf.java:330)
    >> at
    >>

    >
    > org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApp
    > lyTemplates.java:425)
    >
    >> at
    >>

    >
    > org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.jav
    > a:215)
    >
    >> at
    >>

    >
    > org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApp
    > lyTemplates.java:425)
    >
    >> at
    >>

    >
    > org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.jav
    > a:215)
    >
    >> at
    >>

    >
    > org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
    > erImpl.java(Compiled
    >
    >>Code))
    >> at org.apache.xalan.templates.ElemIf.execute(ElemIf.java:203)
    >> at
    >>

    >
    > org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
    > erImpl.java:2318)
    >
    >> at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:153)
    >> at
    >>

    >
    > org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApp
    > lyTemplates.java:425)
    >
    >> at
    >>

    >
    > org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.jav
    > a:215)
    >
    >> at
    >>

    >
    > org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
    > erImpl.java:2318)
    >
    >> at
    >>

    >
    > org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:
    > 699)
    >
    >> at
    >>

    >
    > org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApp
    > lyTemplates.java:425)
    >
    >> at
    >>

    >
    > org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.jav
    > a:215)
    >
    >> at
    >>

    >
    > org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
    > erImpl.java:2318)
    >
    >> at
    >>

    >
    > org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(Transformer
    > Impl.java:2185)
    >
    >> at
    >>

    >
    > org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.j
    > ava:1263)
    >
    >> at
    >>

    >
    > org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
    > 671)
    >
    >> at
    >>

    >
    > org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
    > 1179)
    >
    >> at
    >>

    >
    > org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
    > 1157)
    >
    >> at org.apache.xalan.xslt.Process.main(Process.java:1025)
    >>---------
    >>java.lang.ClassCastException
    >> at
    >>

    >
    > org.apache.xpath.axes.FilterExprIteratorSimple.executeFilterExpr(FilterExprI
    > teratorSimple.java(Compiled
    >
    >>Code))
    >> at
    >>

    >
    > org.apache.xpath.axes.FilterExprWalker.setRoot(FilterExprWalker.java(Compile
    > d
    >
    >>Code))
    >> at
    >>

    >
    > org.apache.xpath.axes.WalkingIterator.setRoot(WalkingIterator.java(Compiled
    >
    >>Code))
    >> at
    >>

    >
    > org.apache.xpath.axes.LocPathIterator.executeCharsToContentHandler(LocPathIt
    > erator.java:276)
    >
    >> at
    >>org.apache.xalan.templates.ElemValueOf.execute(ElemValueOf.java:311)
    >> at
    >>

    >
    > org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApp
    > lyTemplates.java:425)
    >
    >> at
    >>

    >
    > org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.jav
    > a:215)
    >
    >> at
    >>

    >
    > org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApp
    > lyTemplates.java:425)
    >
    >> at
    >>

    >
    > org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.jav
    > a:215)
    >
    >> at
    >>

    >
    > org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
    > erImpl.java(Compiled
    >
    >>Code))
    >> at org.apache.xalan.templates.ElemIf.execute(ElemIf.java:203)
    >> at
    >>

    >
    > org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
    > erImpl.java:2318)
    >
    >> at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:153)
    >> at
    >>

    >
    > org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApp
    > lyTemplates.java:425)
    >
    >> at
    >>

    >
    > org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.jav
    > a:215)
    >
    >> at
    >>

    >
    > org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
    > erImpl.java:2318)
    >
    >> at
    >>

    >
    > org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:
    > 699)
    >
    >> at
    >>

    >
    > org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApp
    > lyTemplates.java:425)
    >
    >> at
    >>

    >
    > org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.jav
    > a:215)
    >
    >> at
    >>

    >
    > org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
    > erImpl.java:2318)
    >
    >> at
    >>

    >
    > org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(Transformer
    > Impl.java:2185)
    >
    >> at
    >>

    >
    > org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.j
    > ava:1263)
    >
    >> at
    >>

    >
    > org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
    > 671)
    >
    >> at
    >>

    >
    > org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
    > 1179)
    >
    >> at
    >>

    >
    > org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
    > 1157)
    >
    >> at org.apache.xalan.xslt.Process.main(Process.java:1025)
    >>
    >>================= END =====================
    >>
    >>Any idea, how to access the node stored in $attribute-source?
    >>Thanks in advance,
    >>
    >>Johannes
    >>

    >
    >
    >
     
    Johannes Lebek, Aug 15, 2003
    #2
    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. asd
    Replies:
    3
    Views:
    439
    Arnaud Berger
    May 23, 2005
  2. gavnosis
    Replies:
    0
    Views:
    522
    gavnosis
    Aug 2, 2003
  3. Timo Nentwig

    selecting nodes between other nodes

    Timo Nentwig, Jun 16, 2004, in forum: XML
    Replies:
    1
    Views:
    405
    Patrick TJ McPhee
    Jun 17, 2004
  4. Johnny Ooi

    Looking A Nodes From Within Nodes

    Johnny Ooi, Nov 13, 2004, in forum: XML
    Replies:
    10
    Views:
    656
    Johnny Ooi
    Nov 14, 2004
  5. Replies:
    2
    Views:
    395
Loading...

Share This Page