Q about node-set comparisons, or casting, or maybe variables
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 18
- Joined: Sat Aug 01, 2009 7:52 pm
Q about node-set comparisons, or casting, or maybe variables
It would help if I even knew what sort of question it was... could someone please gently explain to me what's happening here:
Result:
Is there something special about comparing element and attribute nodes? What sort of magical thing is the variable declaration doing here? (Saxon-EE 9.3.0.5 in Oxygen 13.2)
Thanks, --alex.
Code: Select all
<types good="A">
<type>A</type>
<type>B</type>
<type>A</type>
<type>C</type>
</types>
<xsl:template match="types">
<xsl:message select="concat('1: Good=', count(type[. = @good]))"/>
<xsl:variable name="g" select="@good"/>
<xsl:message select="concat('2: Good=', count(type[. = $g]))"/>
</xsl:template>
Result:
Code: Select all
[Saxon-EE]1: Good=0
[Saxon-EE]2: Good=2
Thanks, --alex.
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Q about node-set comparisons, or casting, or maybe variables
Hi,
There's no magic there, it's just XSLT+XPath.
The variable evaluates the XPath(@good) in the context of the types element (from the XSLT) and obtains the actual value of the attribute, which is 'A'.
For the other expressionwhat happens is that the "good" attribute is evaluated in the context of the type element. It's not there, so it fails.
However it works as expected like this (looks starting from the root): or like this (looks at the attribute of the parent):
Regards,
Adrian
There's no magic there, it's just XSLT+XPath.

The variable evaluates the XPath(@good) in the context of the types element (from the XSLT) and obtains the actual value of the attribute, which is 'A'.
For the other expression
Code: Select all
count(type[. = @good]))
However it works as expected like this (looks starting from the root):
Code: Select all
count(type[. = /types/@good])
Code: Select all
count(type[. = parent::node()/@good])
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service