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

Re: XSL Help

  • From: "G. Ken Holman" <gkholman@C...>
  • To: xml-dev@l...
  • Date: Tue, 09 Jan 2001 10:30:45 -0500

xsl help
At 01/01/09 19:49 +0530, Kumar V. wrote:
>       Kindly suggest me how to transform values of a single attribute to 
> multiple hrefs using XSL or provide me the guidelines/idea how to do it.

XSL, XSLT and XPath questions would be better posted to the following list:

   http://www.mulberrytech.com/xsl/xsl-list

There are a number of subscribers who would enthusiastically respond to 
such questions.

There is also an *excellent* FAQ at:

   http://www.dpawson.co.uk

>       Input:
>       <cit id="d1 d2 d3"/>
>
>      Output:
>       <a href="1"/> <a href="2"/> <a href="3"/>

Note in the code below that the use of normalize-space makes the syntax of 
the multiple token attribute predictable.

I hope this helps.

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

p.s. you may be interested to see our web site for our book (personal, and 
unlimited site and world staff licenses available; all with no-charge 
perpetual updates) and for our deliveries and licensing of our 
instructor-led training derived from the book

T:\ftemp>type test.xml
<cit id="d1 d2 d3"/>
T:\ftemp>type test.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 version="1.0">

<xsl:template match="cit">
   <xsl:call-template name="do-each-token">
     <xsl:with-param name="tokens" select="normalize-space(@id)"/>
   </xsl:call-template>
</xsl:template>

        <!--iterate through each token, generating each element-->
<xsl:template name="do-each-token">
   <xsl:param name="tokens"/>
   <xsl:if test="$tokens">               <!--tokens still exist-->
     <xsl:choose>
       <xsl:when test="contains($tokens,' ')"><!--more than one-->
         <xsl:call-template name="do-an-element">
           <xsl:with-param name="token"
                          select="substring-before($tokens,' ')"/>
         </xsl:call-template>
         <xsl:call-template name="do-each-token">   <!--do next-->
           <xsl:with-param name="tokens"
                           select="substring-after($tokens,' ')"/>
         </xsl:call-template>
       </xsl:when>
       <xsl:otherwise><!--only one token left-->
         <xsl:call-template name="do-an-element">
           <xsl:with-param name="token" select="$tokens"/>
         </xsl:call-template>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:if>
</xsl:template>

                  <!--handle the presence of each single token-->
<xsl:template name="do-an-element">
   <xsl:param name="token"/>
   <a href="{substring($token,2)}"/>
</xsl:template>

</xsl:stylesheet>

T:\ftemp>xt test.xml test.xsl
<?xml version="1.0" encoding="utf-8"?>
<a href="1"/><a href="2"/><a href="3"/>
T:\ftemp>


--
G. Ken Holman                      mailto:gkholman@C...
Crane Softwrights Ltd.               http://www.CraneSoftwrights.com/x/
Box 266, Kars, Ontario CANADA K0A-2E0     +1(613)489-0999   (Fax:-0995)
Web site:     XSL/XML/DSSSL/SGML/OmniMark services, training, products.
Book:   Practical Transformation Using XSLT and XPath ISBN1-894049-05-5
Article: What is XSLT? http://www.xml.com/pub/2000/08/holman/index.html
Next public instructor-led training:             2001-01-27,2001-02-21,
-                            2001-02-27/03-01,2001-03-05/07,2001-03-21,
-                                   2001-04-06/07,2001-05-01,2001-09-19


  • References:
    • XSL Help
      • From: "Kumar V." <vkumar@t...>

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
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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.