[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: Hermann Stamm-Wilbrandt <STAMMW@xxxxxxxxxx>
Date: Thu, 26 Nov 2009 12:11:47 +0100
Re:  Value of the variable
Florent,

> What if you have something like:
>    a, b, <i>c, d</i>
> or:
>    a, b, <i>c</i>d
> ?

that does not seem to be a problem since that may be solved
with your solution on a node basis (Joga's input was in a
<p> node):

$ cat inp1.xml
<p>a, b, <i>c, d</i></p>
$ xpath "count(/p/node())" inp1.xml
2
$ xpath "/p/node()[1]" inp1.xml
a, b,
$ xpath "/p/node()[2]" inp1.xml
<i>c, d</i>
$
$ cat inp2.xml
<p>a, b, <i>c</i>d</p>
$ xpath "count(/p/node())" inp2.xml
3
$ xpath "/p/node()[1]" inp2.xml
a, b,
$ xpath "/p/node()[2]" inp2.xml
<i>c</i>
$ xpath "/p/node()[3]" inp2.xml
d
$


Mit besten Gruessen / Best wishes,

Hermann Stamm-Wilbrandt
Developer, XML Compiler
WebSphere DataPower SOA Appliances
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294


                                                                           
             Florent Georges                                               
             <lists@xxxxxxxxxx                                             
             rg>                                                        To 
                                       xsl-list@xxxxxxxxxxxxxxxxxxxxxx     
             11/26/2009 10:58                                           cc 
             AM                                                            
                                                                   Subject 
                                       Re:  Value of the variable     
             Please respond to                                             
             xsl-list@xxxxxxxx                                             
              lberrytech.com                                               
                                                                           
                                                                           
                                                                           




Joga Singh Rawat wrote:

>     If I have "a, b, <i>c</i>,
> <b>d</i>" I want to get [...]
> ==>OK!!! The output should be
> <a-g><a>a</a><a>b</a><a><i>c</i></a><a><b>d</b></a></a-g>

  So your input structure is driven by both the input's structure
and the input's string value format.  The answer thus depends on
how both relate to each other.  What if you have something like:

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

or:

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

?

  For your initial sample and the first sample here above, you
should be able to use something like this (not tested!):

    <xsl:template match="node()" mode="my:tokenize" priority="10">
       <xsl:variable name="nodes" as="item()+">
          <xsl:next-match/>
       </xsl:variable>
       <xsl:for-each select="$nodes">
          <a>
             <xsl:sequence select="."/>
          </a>
       </xsl:for-each>
    </xsl:template>

    <xsl:template match="text()" mode="my:tokenize">
       <xsl:value-of select="tokenize(., '\s*,\s*')"/>
    </xsl:template>

    <xsl:template match="i|b" mode="my:tokenize">
       <xsl:for-each select="tokenize(., '\s*,\s*')">
          <xsl:copy>
             <xsl:value-of select="."/>
          </xsl:copy>
       </xsl:for-each>
    </xsl:template>

--
Florent Georges
http://www.fgeorges.org/

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.