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

Re: modifiing string based on other nodes

Subject: Re: modifiing string based on other nodes
From: "Bob DuCharme" <bob@xxxxxxxxx>
Date: Wed, 27 Jun 2001 10:52:00 -0400
modifiing
> hai everybody
> I just got one problem and can anybody solve it:
>
> here is the sample xml file:
>
> (text omitted)
>
> what i want is:
> <PermanentName>S_LDD_DBMS_DATA_TYPE</PermanentName>
> <Value DataType="STRING">NUMBER</Value>,which is there
> in the line number4 of above xml file to be
>
> (more omitted)

The stylesheet below doesn't do everything you need, because demonstrates
the parts of XSLT that should handle all your program logic. The second
template rule copies all source tree nodes except for Value elements whose
DataType attribute has a value of INTEGER. The first template rule, for
these Value elements, adds an element to the result tree using an
xsl:element element and an xsl:attribute element. The xsl:attribute element
has program logic to figure out the value of the DataType attribute. If the
element's content has no period in it (the "precision=0" part), it checks
the content value and sets the DataType value appropriately.

Bob DuCharme            www.snee.com/bob             <bob@
snee.com>      see http://www.snee.com/bob/xsltquickly for
info on new book "XSLT Quickly" from Manning Publications.

<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0">

<xsl:template match="Value[@DataType='INTEGER']">

<!-- Need to reference it a lot, so declare var  -->
  <xsl:variable name="val" select="."/>

    <xsl:element name="Value">

      <xsl:attribute name="DataType">
        <xsl:if test="not(contains($val,'.'))">
          <xsl:choose>
            <xsl:when test="$val &lt; 4">
              <xsl:text>SMALL INTEGER</xsl:text>
            </xsl:when>
            <xsl:when test="$val &gt; 15">
              <xsl:text>S_LDD_PRECISION</xsl:text>
            </xsl:when>
            <xsl:when test="($val &gt; 4) and ($val &lt; 15)">
              <xsl:text>BIG_INT</xsl:text>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="@DataType"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:if>
      </xsl:attribute>

    <xsl:apply-templates/> <!-- output actual value -->

  </xsl:element>

</xsl:template>

<!-- Just copy everything else -->
<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>



 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.