[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Value of the variable

Subject: RE: Value of the variable
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 26 Nov 2009 18:02:52 +0530
RE:  Value of the variable
Interestingly, this question was asked about an hour ago on LinkedIn. The poster of that question gave an explicit input and an explicit output, so it was very easy to be able to answer.

She has a requirement for a comma separating the tokens, which is different than the original poster on this thread, but that is easily removed from the solution I posted to LinkedIn:

t:\ftemp>type siddhi.xml
<book>xxx, xxxxxx, xxxxxxxxxxx, <i>xxx</i></book>

t:\ftemp>xslt2 siddhi.xml siddhi.xsl
<?xml version="1.0" encoding="UTF-8"?><book><key>xxx</key>, <key>xxxxxx</key>, <key>xxxxxxxxxxx</key>, <key><i>xxx</i></key></book>
t:\ftemp>type siddhi.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">


<xsl:template match="book">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates mode="make-tokens"/>
  </xsl:copy>
</xsl:template>

<!--tokenize and wrap any text node children-->
<xsl:template match="text()" mode="make-tokens">
  <xsl:for-each select="tokenize(.,', ')[normalize-space()]">
    <key><xsl:value-of select="."/></key>
    <xsl:if test="position()!=last()">, </xsl:if>
  </xsl:for-each>
  <xsl:if test="position()!=last()">, </xsl:if>
</xsl:template>

<!--simply wrap any element children-->
<xsl:template match="*" mode="make-tokens">
  <key>
    <xsl:copy-of select="."/>
    <xsl:if test="position()!=last()">, </xsl:if>
  </key>
</xsl:template>

</xsl:stylesheet>

t:\ftemp>


At 2009-11-26 14:35 +0530, I wrote:
At 2009-11-26 14:27 +0530, Joga Singh Rawat wrote:
What _exactly_ do you want returned from "a, b, <i>c</i>, <b>d</i>"?  If
people do not tell us what they want, it is difficult (and a waste of
volunteer time) to keep guessing what people are asking for.

==>Sorry ken, I can understand that. What I thought that if I get the value
in the variable then I can do it easily. I was trying to do below

<xsl:template match="p">
 <xsl:variable name="txt-with-node" select="."/>
 <a-g>
   <xsl:for-each select="tokenize($txt-with-node,', ')">
    <a><xsl:value-of select="."/></a>
  </a-z>
 </xsl:if>
</xsl:template>

Sorry, Joga, you are showing us what you are doing, you are still not showing us _exactly_ what you want. And, the original data and the example above are *not* well-formed XML, so I'm only guessing.


Assuming the input is repaired to be as follows:

"a, b, <i>c</i>, <b>d</b>"

Do you want the result to be:

  <a-g>
    <a>a</a>
    <a>b</a>
    <a>c</a>
    <a>d</a>
  </a-g>

Do you want the result to be:

  <a-g>
    <a>a</a>
    <a>b</a>
    <a><i>c</i></a>
    <a><b>d</b></a>
  </a-g>

Do you want the result to be something else?

The answer we volunteers can give you will depend on _exactly_ what you want. We are still being asked to guess.

. . . . . . . . . . . Ken


--
Vote for your XML training:   http://www.CraneSoftwrights.com/m/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/m/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/m/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.