OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 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@CraneSoftwrights.com
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