xsl-list
[Top] [All Lists]

namespace question

2005-01-12 21:17:11
I found a very similar version of the following xml and xsl online. In this 
code namespaces are used
in order to subtract the sums for us and them. My xml code is structured 
similarly, and was summing
values for all of the xml. The xsl now needs to subtract in a similar way to 
this example. Is this the 
best way to do it? By assigning namespaces to the xml tags? Or is there a 
better alternative?

Thanks,
dmitri




<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0"

xmlns:us="www.uss.com"
  xmlns:them="www.them.com"> 
        
        

<xsl:template match="asummary">
Sum of values for each namespace: 
<xsl:value-of select="format-number(sum(//us:value) - sum(//them:value),
'###,###,##0.00')" /> 
Sum of all 'value' elements regardless of namespace: 
<xsl:value-of select="format-number(sum(//*[local-name() = 'value']),
'###,###,##0.00')" />
</xsl:template>
</xsl:stylesheet> 




<asummary>

<summary>
<us:item xmlns:us="www.uss.com">   
<us:value>1000</us:value>
</us:item>

<us:item xmlns:us="www.uss.com">   
<us:value>4000</us:value>
</us:item>

<them:item xmlns:them="www.them.com">   
<them:value>1000</them:value>
</them:item>

<them:item xmlns:them="www.them.com">   
<them:value>2500</them:value>
</them:item>
</summary>

<summary>
<us:item xmlns:us="www.uss.com">   
<us:value>1000</us:value>
</us:item>

<us:item xmlns:us="www.uss.com">   
<us:value>2000</us:value>
</us:item>

<them:item xmlns:them="www.them.com">   
<them:value>1000</them:value>
</them:item>

<them:item xmlns:them="www.them.com">   
<them:value>2000</them:value>
</them:item>
</summary>

</asummary>




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>
  • namespace question, dmitrik <=