By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,221 Members | 1,604 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,221 IT Pros & Developers. It's quick & easy.

XSLT: nodes in variables

P: n/a
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:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</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(Ele mValueOf.java:330)
at
org.apache.xalan.templates.ElemApplyTemplates.tran sformSelectedNodes(ElemApplyTemplates.java:425)
at
org.apache.xalan.templates.ElemApplyTemplates.exec ute(ElemApplyTemplates.java:215)
at
org.apache.xalan.templates.ElemApplyTemplates.tran sformSelectedNodes(ElemApplyTemplates.java:425)
at
org.apache.xalan.templates.ElemApplyTemplates.exec ute(ElemApplyTemplates.java:215)
at
org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java(Compiled
Code))
at org.apache.xalan.templates.ElemIf.execute(ElemIf.j ava:203)
at
org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2318)
at org.apache.xalan.templates.ElemCopy.execute(ElemCo py.java:153)
at
org.apache.xalan.templates.ElemApplyTemplates.tran sformSelectedNodes(ElemApplyTemplates.java:425)
at
org.apache.xalan.templates.ElemApplyTemplates.exec ute(ElemApplyTemplates.java:215)
at
org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2318)
at
org.apache.xalan.templates.ElemLiteralResult.execu te(ElemLiteralResult.java:699)
at
org.apache.xalan.templates.ElemApplyTemplates.tran sformSelectedNodes(ElemApplyTemplates.java:425)
at
org.apache.xalan.templates.ElemApplyTemplates.exec ute(ElemApplyTemplates.java:215)
at
org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2318)
at
org.apache.xalan.transformer.TransformerImpl.apply TemplateToNode(TransformerImpl.java:2185)
at
org.apache.xalan.transformer.TransformerImpl.trans formNode(TransformerImpl.java:1263)
at
org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:671)
at
org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:1179)
at
org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:1157)
at org.apache.xalan.xslt.Process.main(Process.java:10 25)
---------
java.lang.ClassCastException
at
org.apache.xpath.axes.FilterExprIteratorSimple.exe cuteFilterExpr(FilterExprIteratorSimple.java(Compi led
Code))
at
org.apache.xpath.axes.FilterExprWalker.setRoot(Fil terExprWalker.java(Compiled
Code))
at
org.apache.xpath.axes.WalkingIterator.setRoot(Walk ingIterator.java(Compiled
Code))
at
org.apache.xpath.axes.LocPathIterator.executeChars ToContentHandler(LocPathIterator.java:276)
at
org.apache.xalan.templates.ElemValueOf.execute(Ele mValueOf.java:311)
at
org.apache.xalan.templates.ElemApplyTemplates.tran sformSelectedNodes(ElemApplyTemplates.java:425)
at
org.apache.xalan.templates.ElemApplyTemplates.exec ute(ElemApplyTemplates.java:215)
at
org.apache.xalan.templates.ElemApplyTemplates.tran sformSelectedNodes(ElemApplyTemplates.java:425)
at
org.apache.xalan.templates.ElemApplyTemplates.exec ute(ElemApplyTemplates.java:215)
at
org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java(Compiled
Code))
at org.apache.xalan.templates.ElemIf.execute(ElemIf.j ava:203)
at
org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2318)
at org.apache.xalan.templates.ElemCopy.execute(ElemCo py.java:153)
at
org.apache.xalan.templates.ElemApplyTemplates.tran sformSelectedNodes(ElemApplyTemplates.java:425)
at
org.apache.xalan.templates.ElemApplyTemplates.exec ute(ElemApplyTemplates.java:215)
at
org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2318)
at
org.apache.xalan.templates.ElemLiteralResult.execu te(ElemLiteralResult.java:699)
at
org.apache.xalan.templates.ElemApplyTemplates.tran sformSelectedNodes(ElemApplyTemplates.java:425)
at
org.apache.xalan.templates.ElemApplyTemplates.exec ute(ElemApplyTemplates.java:215)
at
org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2318)
at
org.apache.xalan.transformer.TransformerImpl.apply TemplateToNode(TransformerImpl.java:2185)
at
org.apache.xalan.transformer.TransformerImpl.trans formNode(TransformerImpl.java:1263)
at
org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:671)
at
org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:1179)
at
org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:1157)
at org.apache.xalan.xslt.Process.main(Process.java:10 25)

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

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

Johannes

Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" <re****************@domain.com> wrote in message
news:bh**********@sp15at20.hursley.ibm.com...
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:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</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(E lemValueOf.java:330)
at


org.apache.xalan.templates.ElemApplyTemplates.tran sformSelectedNodes(ElemApp
lyTemplates.java:425)
at


org.apache.xalan.templates.ElemApplyTemplates.exec ute(ElemApplyTemplates.jav
a:215)
at


org.apache.xalan.templates.ElemApplyTemplates.tran sformSelectedNodes(ElemApp
lyTemplates.java:425)
at


org.apache.xalan.templates.ElemApplyTemplates.exec ute(ElemApplyTemplates.jav
a:215)
at


org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(Transform
erImpl.java(Compiled
Code))
at org.apache.xalan.templates.ElemIf.execute(ElemIf.j ava:203)
at


org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(Transform
erImpl.java:2318)
at org.apache.xalan.templates.ElemCopy.execute(ElemCo py.java:153)
at


org.apache.xalan.templates.ElemApplyTemplates.tran sformSelectedNodes(ElemApp
lyTemplates.java:425)
at


org.apache.xalan.templates.ElemApplyTemplates.exec ute(ElemApplyTemplates.jav
a:215)
at


org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(Transform
erImpl.java:2318)
at


org.apache.xalan.templates.ElemLiteralResult.execu te(ElemLiteralResult.java:
699)
at


org.apache.xalan.templates.ElemApplyTemplates.tran sformSelectedNodes(ElemApp
lyTemplates.java:425)
at


org.apache.xalan.templates.ElemApplyTemplates.exec ute(ElemApplyTemplates.jav
a:215)
at


org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(Transform
erImpl.java:2318)
at


org.apache.xalan.transformer.TransformerImpl.apply TemplateToNode(Transformer
Impl.java:2185)
at


org.apache.xalan.transformer.TransformerImpl.trans formNode(TransformerImpl.j
ava:1263)
at


org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:
671)
at


org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:
1179)
at


org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:
1157)
at org.apache.xalan.xslt.Process.main(Process.java:10 25)
---------
java.lang.ClassCastException
at


org.apache.xpath.axes.FilterExprIteratorSimple.exe cuteFilterExpr(FilterExprI
teratorSimple.java(Compiled
Code))
at


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


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


org.apache.xpath.axes.LocPathIterator.executeChars ToContentHandler(LocPathIt
erator.java:276)
at
org.apache.xalan.templates.ElemValueOf.execute(E lemValueOf.java:311)
at


org.apache.xalan.templates.ElemApplyTemplates.tran sformSelectedNodes(ElemApp
lyTemplates.java:425)
at


org.apache.xalan.templates.ElemApplyTemplates.exec ute(ElemApplyTemplates.jav
a:215)
at


org.apache.xalan.templates.ElemApplyTemplates.tran sformSelectedNodes(ElemApp
lyTemplates.java:425)
at


org.apache.xalan.templates.ElemApplyTemplates.exec ute(ElemApplyTemplates.jav
a:215)
at


org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(Transform
erImpl.java(Compiled
Code))
at org.apache.xalan.templates.ElemIf.execute(ElemIf.j ava:203)
at


org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(Transform
erImpl.java:2318)
at org.apache.xalan.templates.ElemCopy.execute(ElemCo py.java:153)
at


org.apache.xalan.templates.ElemApplyTemplates.tran sformSelectedNodes(ElemApp
lyTemplates.java:425)
at


org.apache.xalan.templates.ElemApplyTemplates.exec ute(ElemApplyTemplates.jav
a:215)
at


org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(Transform
erImpl.java:2318)
at


org.apache.xalan.templates.ElemLiteralResult.execu te(ElemLiteralResult.java:
699)
at


org.apache.xalan.templates.ElemApplyTemplates.tran sformSelectedNodes(ElemApp
lyTemplates.java:425)
at


org.apache.xalan.templates.ElemApplyTemplates.exec ute(ElemApplyTemplates.jav
a:215)
at


org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(Transform
erImpl.java:2318)
at


org.apache.xalan.transformer.TransformerImpl.apply TemplateToNode(Transformer
Impl.java:2185)
at


org.apache.xalan.transformer.TransformerImpl.trans formNode(TransformerImpl.j
ava:1263)
at


org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:
671)
at


org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:
1179)
at


org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:
1157)
at org.apache.xalan.xslt.Process.main(Process.java:10 25)

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

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

Johannes



Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.