Hi All,
I am writing an XSL to transform the XML to XML.Only change i need in xml is to add the value for the price element
under book tag for which publisher location is "World".
The value for the price tag should be the sum of the value of price tag of two book tags (location for one is US and location of other is India).
here is the snippets from the code:
please get back to me today if you can help in any way.
thanks
Shakil
I am writing an XSL to transform the XML to XML.Only change i need in xml is to add the value for the price element
under book tag for which publisher location is "World".
The value for the price tag should be the sum of the value of price tag of two book tags (location for one is US and location of other is India).
here is the snippets from the code:
Code:
book.xml --------------------------------------------------- <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="test.xsl"?> <booklist> <book> <publisher> <location>India</location> <identity id="111">book.com</identity> </publisher> <title>bookname1</title> <price>80</price> </book> <book> <publisher> <location>US</location> <identity id="222">usbook.com</identity> </publisher> <title>bookname2</title> <price>60</price> </book> <book> <publisher> <location>UK</location> <identity id="333">ukbook.com</identity> </publisher> <title>bookname3</title> <price>50</price> </book> <book> <publisher> <location>Singapore</location> <identity id="444">sgbook.com</identity> </publisher> <title>bookname4</title> <price>50</price> </book> <book> <publisher> <location>World</location> <identity id="000">worldbook.com</identity> </publisher> <title>bookname5</title> <price></price> </book> </booklist> ---------------------------------------------------
Code:
----------------book.xsl-------------------------- <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" media-type="text/xml" omit-xml-declaration="yes" version="1.0" /> <xsl:template match="/ | @* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="bookList/book" > <xsl:copy> <xsl:apply-templates select="@* | node()"/> <xsl:if test="(publisher/location = 'India')"> <xsl:if test="(publisher/identity[@id] = '111')"> <xsl:variable name="A1SoloTotal"><xsl:value-of select="//booklist/book/price"/></xsl:variable> </xsl:if> </xsl:if> <xsl:if test="(publisher/location = 'US')"> <xsl:if test="(publisher/identity[@id] = '222')"> <xsl:variable name="A2SoloTotal"><xsl:value-of select="//booklist/book/price"/></xsl:variable> </xsl:if> </xsl:if> <xsl:if test="(publisher/location = 'World')"> <xsl:if test="(publisher/identity[@id] = '000')"> <price><xsl:value-of select='$A1SoloTotal'+'$A2SoloTotal'/></price> </xsl:if> </xsl:if> </xsl:copy> </xsl:template> </xsl:stylesheet>
please get back to me today if you can help in any way.
thanks
Shakil
Comment