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

RE: [Fwd: CLARIFICATION IN XML 2 XML TRANSFORMATION]

Subject: RE: [Fwd: CLARIFICATION IN XML 2 XML TRANSFORMATION]
From: <Jarno.Elovirta@xxxxxxxxx>
Date: Thu, 21 Oct 2004 11:06:20 +0300
x2013
Hi,

> I am transforming the XML one to another format. I have an
> instant in my
> input xml tree like below
>
> <cross-ref refid="bib2 bib4 bib5
> bib6"><sup>2,4&ndash;6</sup></cross-ref>.
>
> And, after the transformation I need result as below
>
> <sup><a href="#bib2">2</a>, <a href="#bib4">4</a>, <a
> href="#bib5">5</a>, <a href="#bib6">6</a></sup>
>
> Please advise, hot to achieve this.

  <xsl:template match="cross-ref">
    <sup>
      <xsl:call-template name="tokenizer">
        <xsl:with-param name="refids" select="@refid"/>
        <xsl:with-param name="text">
          <xsl:call-template name="expand">
            <xsl:with-param name="text" select="."/>
          </xsl:call-template>
        </xsl:with-param>
      </xsl:call-template>
    </sup>
  </xsl:template>
  <xsl:template name="tokenizer">
    <xsl:param name="refids" select="''"/>
    <xsl:param name="text" select="''"/>
    <xsl:choose>
      <xsl:when test="contains($refids, ' ')">
        <a href="#{substring-before($refids, ' ')}">
          <xsl:value-of select="substring-before($text, ',')"/>
        </a>
        <xsl:text>, </xsl:text>
        <xsl:call-template name="tokenizer">
          <xsl:with-param name="refids" select="substring-after($refids, '
')"/>
          <xsl:with-param name="text" select="substring-after($text, ',')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <a href="#{$refids}">
          <xsl:value-of select="$text"/>
        </a>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="expand">
    <xsl:param name="text" select="''"/>
    <xsl:choose>
      <xsl:when test="contains($text, ',')">
        <xsl:choose>
          <xsl:when test="contains(substring-before($text, ','),
'&#x2013;')">
            <xsl:call-template name="range">
              <xsl:with-param name="start" select="substring-before($text,
'&#x2013;')"/>
              <xsl:with-param name="end"
select="substring-before(substring-after($text, '&#x2013;'), ',')"/>
            </xsl:call-template>
            <xsl:text>,</xsl:text>
            <xsl:call-template name="expand">
              <xsl:with-param name="text" select="substring-after($text,
',')"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="substring-before($text, ',')"/>
            <xsl:text>,</xsl:text>
            <xsl:call-template name="expand">
              <xsl:with-param name="text" select="substring-after($text,
',')"/>
            </xsl:call-template>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:choose>
          <xsl:when test="contains($text, '&#x2013;')">
            <xsl:call-template name="range">
              <xsl:with-param name="start" select="substring-before($text,
'&#x2013;')"/>
              <xsl:with-param name="end" select="substring-after($text,
'&#x2013;')"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$text"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="range">
    <xsl:param name="start" select="0"/>
    <xsl:param name="end" select="0"/>
    <xsl:choose>
      <xsl:when test="not($start = $end)">
        <xsl:value-of select="$start"/>
        <xsl:text>,</xsl:text>
        <xsl:call-template name="range">
          <xsl:with-param name="start" select="$start + 1"/>
          <xsl:with-param name="end" select="$end"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$start"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

Cheers,

Jarno - Suicide Commando: Face Of Death (Waking Up The Dancefloor Mix by
Implant)

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.