Get Text from Nodeset
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 25
- Joined: Sun Apr 22, 2018 10:17 pm
Get Text from Nodeset
Hi everybody, I work in xslt 1..0 and I have just get an Array and convert it to a Node Set by the msxsl:node-set() function so i get an array with 12 elements as you can see in the code, but which sentence I need to introduce for getting an text value of for example position 3 of the array I think that i've tested all the possibilities and I always get a Nodeset and not a text value
<xsl:variable name="urlSchema" select="string('http://www.info.es/es/fr/data/2017-09-12/space.xsd')" /> --> Array by split by the / character
<xsl:variable name="arraySchema">
<xsl:call-template name="split">
<xsl:with-param name="str" select="$urlSchema" />
<xsl:with-param name="splitString" select="'/'" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="cvt" select="msxsl:node-set($arraySchema)" /> --> convert into Array
<xsl:variable name="Totcvt" select="$cvt/node()" /> ---> now it has 12 elements
<xsl:variable name="uno" select="$Totcvt[3]" /> ---- access to third element (nodeset)
<xsl:variable name="dos" select="$uno/text()" /> --> also nodeset
<xsl:variable name="cuenta" select="count($Totcvt)" /> ---> number 12
Which Sentence for getting Text and not Nodeset ???
<xsl:template match="/">
<xsl:copy-of select="$uno"/>
<xsl:copy-of select="$dos"/>
<xsl:value-of select="$cuenta"/>
</xsl:template>
Best Regards
<xsl:variable name="urlSchema" select="string('http://www.info.es/es/fr/data/2017-09-12/space.xsd')" /> --> Array by split by the / character
<xsl:variable name="arraySchema">
<xsl:call-template name="split">
<xsl:with-param name="str" select="$urlSchema" />
<xsl:with-param name="splitString" select="'/'" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="cvt" select="msxsl:node-set($arraySchema)" /> --> convert into Array
<xsl:variable name="Totcvt" select="$cvt/node()" /> ---> now it has 12 elements
<xsl:variable name="uno" select="$Totcvt[3]" /> ---- access to third element (nodeset)
<xsl:variable name="dos" select="$uno/text()" /> --> also nodeset
<xsl:variable name="cuenta" select="count($Totcvt)" /> ---> number 12
Which Sentence for getting Text and not Nodeset ???
<xsl:template match="/">
<xsl:copy-of select="$uno"/>
<xsl:copy-of select="$dos"/>
<xsl:value-of select="$cuenta"/>
</xsl:template>
Best Regards
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Get Text from Nodeset
Hi,
The 'split' template is missing from your code. We need that to establish what you put in 'arraySchema' in the first place.
Regards,
Adrian
The 'split' template is missing from your code. We need that to establish what you put in 'arraySchema' in the first place.
Regards,
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
-
- Posts: 25
- Joined: Sun Apr 22, 2018 10:17 pm
Re: Get Text from Nodeset
I send it
<xsl:template name="split">
<xsl:param name="str" select="."/>
<xsl:param name="splitString" />
<xsl:choose>
<xsl:when test="contains($str,$splitString)">
<data>
<xsl:value-of select="substring-before($str,$splitString)"/>
</data>
<xsl:call-template name="split">
<xsl:with-param name="str"
select="substring-after($str,$splitString)"/>
<xsl:with-param name="splitString" select="$splitString"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<data>
<xsl:value-of select="$str"/>
</data>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="split">
<xsl:param name="str" select="."/>
<xsl:param name="splitString" />
<xsl:choose>
<xsl:when test="contains($str,$splitString)">
<data>
<xsl:value-of select="substring-before($str,$splitString)"/>
</data>
<xsl:call-template name="split">
<xsl:with-param name="str"
select="substring-after($str,$splitString)"/>
<xsl:with-param name="splitString" select="$splitString"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<data>
<xsl:value-of select="$str"/>
</data>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Get Text from Nodeset
You're splitting by '/' and your split template uses elements named 'data', so you're getting in $arraySchema:
Not sure why yours had 12. I see only 8 on this example ('http://www.info.es/es/fr/data/2017-09-12/space.xsd').
Anyway, if you just want to get to the text use: Where data[8] is the eighth ('space.xsd').
Regards,
Adrian
Code: Select all
<data>http:</data>
<data></data>
<data>www.info.es</data>
<data>es</data>
<data>fr</data>
<data>data</data>
<data>2017-09-12</data>
<data>space.xsd</data>
Anyway, if you just want to get to the text use:
Code: Select all
<xsl:value-of select="$cvt/data[8]/text()"/>
Regards,
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
-
- Posts: 25
- Joined: Sun Apr 22, 2018 10:17 pm
Re: Get Text from Nodeset
Thank Adrian, it works an solve my problem, but it's very strange because if I check directly the expresion $cvt/data[$cuenta]/text() it gives the correct data but if Icheck the contains of the variable $uno again yields a nodeset.
but for me it's enough
<xsl:variable name="cuenta" select="count($Totcvt)" />
<xsl:variable name="uno" select="$cvt/data[$cuenta]/text()"/> $uno --> NodeSet (dimension(1))
Again Thanks
but for me it's enough
<xsl:variable name="cuenta" select="count($Totcvt)" />
<xsl:variable name="uno" select="$cvt/data[$cuenta]/text()"/> $uno --> NodeSet (dimension(1))
Again Thanks
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Get Text from Nodeset
Hi,
Convert it to string, if that's what you need: Note that you'll have to use <xsl:value-of select="$uno"/> after this (instead of xsl:copy-of).
Regards,
Adrian
Convert it to string, if that's what you need:
Code: Select all
<xsl:variable name="uno" select="string($cvt/data[$cuenta]/text())"/>
Regards,
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