Re: [xsl] modifiing string based on other nodes

Subject: Re: [xsl] modifiing string based on other nodes
From: "Bob DuCharme" <bob@xxxxxxxxx>
Date: Wed, 27 Jun 2001 10:52:00 -0400
> 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               <bob@>      see for
info on new book "XSLT Quickly" from Manning Publications.

<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<xsl:stylesheet xmlns:xsl="";

<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:when test="$val &lt; 4">
              <xsl:text>SMALL INTEGER</xsl:text>
            <xsl:when test="$val &gt; 15">
            <xsl:when test="($val &gt; 4) and ($val &lt; 15)">
              <xsl:value-of select="@DataType"/>

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



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


 XSL-List info and archive:

Current Thread