This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: string replacement based on other conditions
- To: "'guruprasadv at yahoo dot com'" <guruprasadv at yahoo dot com>
- Subject: RE: [xsl] string replacement based on other conditions
- From: Rene de Vries <RdVries at PCL-HaGe dot nl>
- Date: Tue, 26 Jun 2001 09:35:44 +0200
- Cc: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Organization: PCL HaGé b.v.
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Guru,
If I can asume that your XML is always formed in the same way like:
<ROOT>
<Property>
<Label>Dbms Data Type</Label>
<PermanentName>S_LDD_DBMS_DATA_TYPE</PermanentName>
<Value DataType="STRING">NUMBER</Value>
</Property>
<Property>
<Label>Dbms Data Type Length</Label>
<PermanentName>S_LDD_LEN</PermanentName>
<Value DataType="INTEGER">16</Value>
</Property>
<Property>
<Label>Data Storage Precision</Label>
<PermanentName>S_LDD_PRECISION</PermanentName>
<Value DataType="INTEGER">1</Value>
</Property>
</ROOT>
You can use this:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="ROOT">
<xsl:element name="ROOT">
<xsl:apply-templates select="Property"/>
</xsl:element>
</xsl:template>
<xsl:template match="Property">
<xsl:choose>
<xsl:when test="Label='Dbms Data Type'">
<xsl:variable name="Length">
<xsl:value-of select="../Property[position()=2]/Value"/>
</xsl:variable>
<xsl:variable name="Precision">
<xsl:value-of select="../Property[position()=3]/Value"/>
</xsl:variable>
<xsl:element name="Property">
<xsl:copy-of select="./Label"/>
<xsl:copy-of select="./PermanentName"/>
<xsl:element name="Value">
<xsl:choose>
<xsl:when test="($Length < 4 and $Precision=0)">
<xsl:attribute name="DataType">
<xsl:value-of select="./Value/@DataType"/>
</xsl:attribute>
<xsl:value-of select="'SMALL INTEGER'"/>
</xsl:when>
<xsl:when test="($Length >= 4 and $Length < 15 and $Precision=0)">
<xsl:attribute name="DataType">
<xsl:value-of select="./Value/@DataType"/>
</xsl:attribute>
<xsl:value-of select="'INTEGER'"/>
</xsl:when>
<xsl:when test="($Length > 15 and $Precision=0)">
<xsl:attribute name="DataType">
<xsl:value-of select="./Value/@DataType"/>
</xsl:attribute>
<xsl:value-of select="'BIGINT'"/>
</xsl:when>
<xsl:when test="($Length > 15 and ($Precision=1 or $Precision=2))">
<xsl:attribute name="DataType">
<xsl:value-of select="./Value/@DataType"/>
</xsl:attribute>
<xsl:value-of select="'DECIMAL'"/>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="DataType">
<xsl:value-of select="./Value/@DataType"/>
</xsl:attribute>
<xsl:value-of select="./Value"/>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
success!!
Greetings Rene
{ @ @ }
^
\__/
"You don't need eyes to see, you need vision!"
-----Oorspronkelijk bericht-----
Van: guru prasad [SMTP:guruprasadv@yahoo.com]
Verzonden: maandag 25 juni 2001 11:09
Aan: xsl-list@lists.mulberrytech.com
Onderwerp: [xsl] string replacement based on other conditions
hai everybody,I got a problem.This is a example xml
file .
here is the sample xml file:
<Property>
<Label>Dbms Data Type</Label>
<PermanentName>S_LDD_DBMS_DATA_TYPE</PermanentName>
<Value DataType="STRING">NUMBER</Value> //comment this has to be changed based on conditions
</Property>
<Property>
<Label>Dbms Data Type Length</Label>
<PermanentName>S_LDD_LEN</PermanentName>
<Value DataType="INTEGER">4</Value>
</Property>
<Property>
<Label>Data Storage Precision</Label>
<PermanentName>S_LDD_PRECISION</PermanentName>
<Value DataType="INTEGER">0</Value>
</Property>
what i want is:
<PermanentName>S_LDD_DBMS_DATA_TYPE</PermanentName>
<Value DataType="STRING">NUMBER</Value>,which is there in the above xml file to be
<PermanentName>S_LDD_DBMS_DATA_TYPE</PermanentName>
<Value DataType="STRING">SMALL INTEGER<value> ------NUMBER SHOULD BECOME SMALL INTEGER ONLY IF
<Value DataType="INTEGER">4</Value>---- which has got a value less than 4
<PermanentName>S_LDD_PRECISION</PermanentName>
<Value DataType="INTEGER">0</Value>------ which has got a precision of 0
<PermanentName>S_LDD_DBMS_DATA_TYPE</PermanentName>
<Value DataType="STRING">INTEGER<value> ------NUMBER SHOULD BECOME INTEGER ONLY IF
<Value DataType="INTEGER">4</Value>---- which has got a value between 4 and 15
<PermanentName>S_LDD_PRECISION</PermanentName>
<Value DataType="INTEGER">0</Value>------which has got a precision of zero
<PermanentName>S_LDD_DBMS_DATA_TYPE</PermanentName>
<Value DataType="STRING">BIGINT<value> ------NUMBER SHOULD BECOME BIGINT ONLY IF
<Value DataType="INTEGER">4</Value>---- which has got a value greater than 15
<PermanentName>S_LDD_PRECISION</PermanentName>
<Value DataType="INTEGER">0</Value>----which has got a precision of zero
<PermanentName>S_LDD_DBMS_DATA_TYPE</PermanentName>
<Value DataType="STRING">DECIMAL<value> ------NUMBER SHOULD BECOME DECIMAL ONLY IF
<Value DataType="INTEGER">4</Value>---- which has got a value greater than 15
<PermanentName>S_LDD_PRECISION</PermanentName>
<Value DataType="INTEGER">0</Value>----which has got a precision of 1 or 2
CAN ANYBODY HELP ME IN THIS MATTER
THANKS
GURU
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list