Split String To Array Using XPATH
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 1
- Joined: Fri Jul 22, 2016 12:19 am
Split String To Array Using XPATH
I'm trying to break a string into an array based on the length. for Ex: If I have a string of 30 characters, I want to convert into an array of 5 characters each using an xpath function.
Is there any way to do this? Also, I noticed in this thread - Creating an incremental count variable in XSLT / XPath when using Xpath for..in..return?
that we can use "For" as "For $i in 1 to $length return $i". When I'm trying to use "1 to 5" i.e. constants, xpath is accepting, but when I'm trying to pass a variable " 1 to $length", xpath is not accepting.
Please suggest.
Alex
Is there any way to do this? Also, I noticed in this thread - Creating an incremental count variable in XSLT / XPath when using Xpath for..in..return?
that we can use "For" as "For $i in 1 to $length return $i". When I'm trying to use "1 to 5" i.e. constants, xpath is accepting, but when I'm trying to pass a variable " 1 to $length", xpath is not accepting.
Please suggest.
Alex
-
- Posts: 99
- Joined: Thu Oct 23, 2008 6:29 am
Re: Split String To Array Using XPATH
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<root>
<string>123456789012345678901234567890</string>
</root>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="1.0">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="/root/string">
<xsl:variable name="var" select="substring(.,1,5),substring(.,6,5),substring(.,11,5),substring(.,16,5),substring(.,21,5),substring(.,26,5)"/>
<xsl:text>
</xsl:text>
<xsl:value-of select="$var[1]"/><xsl:text>
</xsl:text>
<xsl:value-of select="$var[2]"/><xsl:text>
</xsl:text>
<xsl:value-of select="$var[3]"/><xsl:text>
</xsl:text>
<xsl:value-of select="$var[4]"/><xsl:text>
</xsl:text>
<xsl:value-of select="$var[5]"/><xsl:text>
</xsl:text>
<xsl:value-of select="$var[6]"/><xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
Code: Select all
12345
67890
12345
67890
12345
67890
Return to “General XML Questions”
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