xsl parse value,parse attribute,xsl parse attribute,xsl parse string,how to parse,xsl analyze string attribute,parse attributes xml xsl,don t parse attribute,seperated in xslt,don t parse xsl, xml%%%xsl parse value - Re: how to parse attribute value seperated by "

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

Re: how to parse attribute value seperated by "|"

Subject: Re: how to parse attribute value seperated by "|"
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 20 Apr 2004 10:00:03 +0100
xsl parse value
Hi,

> I have an element like this:
>
> <para one-of="|11|22|33|44|"/>
>
> I want to get the value list of its attribute"one-of", but I don't
> know how to parse it,

In XSLT 1.0, to parse the one-of attribute, you need to use a
recursive template that parses the string by breaking it at each |.
Something like:

<xsl:template match="@one-of" name="parse-one-of">
  <xsl:param name="list" select="string(.)" />
  <xsl:if test="$list">
    <xsl:variable name="value"
      select="substring-before($list, '|')" />
    ...
    <!-- do something with $value -->
    ...
    <!-- recursive call -->
    <xsl:call-template name="parse-one-of">
      <xsl:with-param name="list"
        select="substring-after($list, '|')" />
    </xsl:call-template>
  </xsl:if>
</xsl:template>

You need to fill in the middle part of the template to do what you
want it to do with each of the values.

In XSLT 2.0, you can use the tokenize() function to split the value of
one-of into a sequence of strings:

  tokenize(@one-of, '|')

You could then iterate over that sequence with an <xsl:for-each>, for
example. Alternatively, you could parse one-of using the
<xsl:analyze-string> instruction. What's most appropriate depends on
what you want to do with the values.

Of course, if all you want to do is test whether a particular value
appears in the one-of attribute, then you don't need to parse it at
all, just do:

  contains(@one-of, concat('|', $value, '|'))

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

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-2013 All Rights Reserved.