Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT Delimited Text Node

Reply
Thread Tools

XSLT Delimited Text Node

 
 
Mike King
Guest
Posts: n/a
 
      02-28-2005
Is there a way in XSLT to match on numbers that are delimited by a character
or space in a text node?


 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      03-01-2005


Mike King wrote:

> Is there a way in XSLT to match on numbers that are delimited by a character
> or space in a text node?


XSLT 2.0 can do that nicely with the tokenize XPath 2.0 function e.g.
with the input being

<?xml version="1.0" encoding="UTF-8"?>
<root>
<data-list>1 2 3 4 5</data-list>
</root>

and the stylesheet

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="2.0">

<xslutput method="xml" indent="yes" />

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>

<xsl:template match="data-list">
<xsl:copy>
<xsl:for-each select="tokenize(., '\s+')">
<data><xsl:value-of select="." /></data>
</xsl:for-each>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

the result using Saxon 8.3 is


<?xml version="1.0" encoding="UTF-8"?>
<root>
<data-list>
<data>1</data>
<data>2</data>
<data>3</data>
<data>4</data>
<data>5</data>
</data-list>
</root>


If you want to use XSLT 1.0 then you need to write a recursive template
taking the string with the numbers as the argument and splitting it up
using XPath 1.0 functions like substring-before, substring-after etc.


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert non-delimited to delimited RyanL Python 6 08-28-2007 12:06 AM
XSLT Child node of a specific node gregmcmullinjr@gmail.com XML 3 10-20-2006 10:05 PM
xsl variable $node/text() but $node can non-node-set help! Tjerk Wolterink XML 2 08-24-2006 03:28 AM
How to set the node indent property between the parent node and the leaf node viveknatani@gmail.com ASP .Net 0 02-13-2006 07:11 PM
XSLT: branching node processing with respect to node type possible? Ralf Wahner XML 2 07-15-2003 04:18 PM



Advertisments