Subject: Re: [xsl] Temporary tree elements and namespaces From: "João C. Morais" <spiderfish@xxxxxxxxx> Date: Thu, 14 Feb 2008 03:49:06 +0000 |
Cheers, Joco
Joco,
I think we're nearly there. Your input XML has no namespaces to deal with; you just need all elements in the output to be in the "required-excel-stylesheet" namespace, correct? If this is the case, you don't need to change or set an xpath default namespace in your stylesheet. You just need to make sure any elements you throw to the output are in the appropriate namespace. For example, this modified version of your XSLT:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:variable name="taxes" as="item()*">
<xsl:for-each select="//value">
<xsl:element name="tax">
<xsl:element name="value">
<xsl:value-of select="format-number(.,'#.00')"/>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:variable>
<xsl:template match="/">
<xsl:element name="DocumentExcelElement" namespace="required-excel-stylesheet">
<xsl:element name="SomeExcelElement" namespace="required-excel-stylesheet">Hello World</xsl:element>
<xsl:element name="SomeOtherExcelElement" namespace="required-excel-stylesheet">
<xsl:value-of select="format-number(sum($taxes//value),'#.00')"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
transforms this:
<?xml version="1.0" encoding="ISO-8859-1"?> <values> <value>0.123</value> <value>0.234</value> </values>
into this:
<?xml version="1.0" encoding="UTF-8"?> <DocumentExcelElement xmlns="required-excel-stylesheet"> <SomeExcelElement>Hello World</SomeExcelElement> <SomeOtherExcelElement>0.35</SomeOtherExcelElement> </DocumentExcelElement>
Is that what you are looking for? Note also that I changed sum($taxes/value) to sum($taxes//value)...otherwise I always got 0.00...
Cheers,
...sam
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Temporary tree elements a, Sam Byland | Thread | RE: [xsl] Temporary tree elements a, marrocdanderfluff |
Re: [xsl] Temporary tree elements a, Sam Byland | Date | RE: [xsl] Extracting text between n, Michael Kay |
Month |