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

Re: Splitting attributes

Subject: Re: Splitting attributes
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 18 Nov 2002 11:58:06 -0500
xsl iterate attributes
Endre,

Also, if your IDREFS attribute actually happens to point to IDs (which they should, as IDREFs), and if the IDs are declared in a DTD available to the transformation, you can exploit a feature of the id() function. id() will work with IDREFS values, so if you said

<xsl:template match="Class">
  <xsl:for-each select="id(@subtypes)">
  ...
  </xsl:for-each>
</xsl:template>

The for-each will iterate over the nodes that carry the ID attributes corresponding to your IDREFS value. Even if you don't actually want to process those nodes, it's a cheap way of getting to the IDREFS values separately (since of course they'll also be the IDs on the nodes retrieved by the function).

See XPath 4.1 for the lowdown on id().

Cheers,
Wendell

At 02:10 AM 11/18/2002, Oleg wrote:
Endre Magyari wrote:
    In my source XML I have elements with IDREFS attributes, like:
    <Class subtypes="id1 id23 id56 id34">
    My desire is to generate an element for each idref in part.(Split the
attribute to idrefs)
    Any idea how to do this? I haven't seen any splitting functions in the
XPATH documentation. Mostly, I would like  an <xsl:for-each>-like behaviour
to iterate on the set of the strings resulted from splitting the attribute
value.

You can make use substring-before($value, ' ') function recursively to get tokens. I'd better use standard templates either from exslt[1] or fxsl[2] libraries, but just to give you idea, here is a sample template:


<xsl:template match="Class">
<xsl:call-template name="tokenize">
<xsl:with-param name="str" select="normalize-space(@subtypes)"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="tokenize">
<xsl:param name="str"/>
<xsl:if test="string-length($str) > 0">
<token>
<xsl:choose>
<xsl:when test="contains($str, ' ')">
<xsl:value-of select="substring-before($str, ' ')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$str"/>
</xsl:otherwise>
</xsl:choose>
</token>
<xsl:call-template name="tokenize">
<xsl:with-param name="str" select="normalize-space(substring-after($str, ' '))"/>
</xsl:call-template>
</xsl:if>
</xsl:template>


[1] http://www.exslt.org/str/functions/tokenize/index.html
[2] http://www.topxml.com/xsl/articles/dice/#res3
--
Oleg Tkachenko
eXperanto team
Multiconn Technologies, Israel


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



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.