position() counts two at a time
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 26
- Joined: Wed Aug 24, 2005 10:47 am
position() counts two at a time
Hi,
I try to use position() to give special treatment to the first element of a sequence, the first <realComplement>
This is the template I use:
But the output for $compNr is 2,4,6, whereas the output for xsl:number is 1,2,3.
Any ideas what is going wrong here?
Any hints greatly appreciated,
Frank
I try to use position() to give special treatment to the first element of a sequence, the first <realComplement>
Code: Select all
<realFrame>
<realComplement id="v11c1" status="empty">
<role>eA2+</role>
<ref target="v10c1"/>
</realComplement>
<realComplement id="v11c2">
<role>SRC</role>
<case>DatLoc!</case>
</realComplement>
<realComplement id="v11c3" status="empty">
<role>P2+</role>
<ref target="V0">part/possession of speaker</ref>
</realComplement>
</realFrame>
Code: Select all
<xsl:template match="realComplement">
<xsl:variable name="compNr" select="position()"/>
<xsl:number></xsl:number>
<xsl:text>realComplement-Nummer</xsl:text>
<xsl:value-of select="$compNr"></xsl:value-of>
...
Any ideas what is going wrong here?
Any hints greatly appreciated,
Frank
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi Frank,
The position() function will return the possition of that node in the list of nodes the templates are applied on, that is it depends on how you called apply-templates. You should be aware that although they are not visible when you look at the XML document there are some whitespace only text nodes between your elements.
By default if you have only a template as in your example then it will be activated by an apply-templates from a built-in rule (see http://www.w3.org/TR/xslt#built-in-rule for details) and that means that the default select value is used and that is node() and there are selected not only the elements inside realFrame but also other nodes, in this case the text whitespace only nodes I mentione above. If you add a template like
to select only elements in apply-templates then you will get the same results for position as you get with xsl:number.
The built-in code that is executed in your case is
and you can see that you get with this the same results as you posted.
Best Regards,
George
The position() function will return the possition of that node in the list of nodes the templates are applied on, that is it depends on how you called apply-templates. You should be aware that although they are not visible when you look at the XML document there are some whitespace only text nodes between your elements.
By default if you have only a template as in your example then it will be activated by an apply-templates from a built-in rule (see http://www.w3.org/TR/xslt#built-in-rule for details) and that means that the default select value is used and that is node() and there are selected not only the elements inside realFrame but also other nodes, in this case the text whitespace only nodes I mentione above. If you add a template like
Code: Select all
<xsl:template match="realFrame">
<xsl:apply-templates select="*"/>
</xsl:template>
The built-in code that is executed in your case is
Code: Select all
<xsl:template match="realFrame">
<xsl:apply-templates select="node()"/>
</xsl:template>
Best Regards,
George
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