473,471 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XSLT: nodes in variables

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
1 2729
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: K. N. | last post by:
Is there any good and fast Python module for XSLT processing ? I'm going to use XML and XSLT to generate web pages, so I need XSLT processor that will be able to transform for example a DOM object...
13
by: Martin | last post by:
I have 5 days of experince with XSLT and I am sure my problem is pretty much as basic as they come but I cannot work it out, so I hope someone will take pity on me - please! I have inherited an...
5
by: inquirydog | last post by:
Hi- Does anyone know a way to compare whether two nodes contain the same information in xslt (the name, attributes, and all content recursivly should be the same. I am interested in the case...
4
by: Frederik Sørensen | last post by:
I include a xslt stylesheet with variables for all the error messages in my system. <xsl:variable name="Banner_error_1"> errormessage 1 for banner </xsl:variable> <xsl:variable...
4
by: cyclops | last post by:
I'm trying to do XML + XSLT -> Another XML. The source XML contains multiple namespaces and XSLT will handle all possible tags under each name space. ----source---- <document xmlns="..."...
1
by: Oleg Konovalov | last post by:
Hi, I am new to XSLT, trying to significantly modify somebody else's XSL. That is not 2.0. I need to create min & max variable(s) to be used in many templates and sub-templates based on...
1
by: Daniel Hilgarth | last post by:
Hello, I am currently trying to use XSLT for the creation of multiple HTML-files from a single XML-File. This HTML-files need to have links to each other. The following information might be...
2
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.