Stumped on this XSLT

P

PBR

Hi,

I'm trying to do some grouping on a set elements based on one of the set's
child element values. That seems to work OK. My problem is that I would like
to allow for additional child elements to be added to the source document
and have the XSLT copy them over without explicitly adding them to the XSL
file. My problem is that when I run the transformation in XmlSpy, I just get
back the text of all the nodes, and not the xml tags plus text. If I remove
the namespace from the root element of the source file, then it works as
expected. What do I need to do to the XSLT to make this work and still keep
the namespace in the source file? Samples are below.

Thanks,

P

<Details xmlns="http://someuri">
<Detail>
<EXPORTED>F</EXPORTED>
<EXPOR_DATE/>
<IMPORTED>F</IMPORTED>
<IMPOR_DATE/>
<TRNSXN>30185</TRNSXN>
<REVISION>0</REVISION>
<ESTIM_DATE>20040916</ESTIM_DATE>
<UNIT_ID_A>TEXU</UNIT_ID_A>
<UNIT_ID_N>255532</UNIT_ID_N>
</Detail>
<Detail>
<EXPORTED>F</EXPORTED>
<EXPOR_DATE/>
<IMPORTED>F</IMPORTED>
<IMPOR_DATE/>
<TRNSXN>30189</TRNSXN>
<REVISION>0</REVISION>
<ESTIM_DATE>20040916</ESTIM_DATE>
<UNIT_ID_A>TEXU</UNIT_ID_A>
<UNIT_ID_N>255532</UNIT_ID_N>
</Detail>
<Detail>
<EXPORTED>F</EXPORTED>
<EXPOR_DATE/>
<IMPORTED>F</IMPORTED>
<IMPOR_DATE/>
<TRNSXN>30185</TRNSXN>
<REVISION>0</REVISION>
<ESTIM_DATE>20040916</ESTIM_DATE>
<UNIT_ID_A>TEXU</UNIT_ID_A>
<UNIT_ID_N>255532</UNIT_ID_N>
</Detail>
<Detail>
<EXPORTED>F</EXPORTED>
<EXPOR_DATE/>
<IMPORTED>F</IMPORTED>
<IMPOR_DATE/>
<TRNSXN>30189</TRNSXN>
<REVISION>0</REVISION>
<ESTIM_DATE>20040916</ESTIM_DATE>
<UNIT_ID_A>TEXU</UNIT_ID_A>
<UNIT_ID_N>255538</UNIT_ID_N>
</Detail>
</Details>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:key name="DetailsByUNIT_ID_N" match="Detail" use="UNIT_ID_N"/>
<xsl:template match="Details">
<GroupedContainers>
<xsl:for-each select="Detail[count(. | key('DetailsByUNIT_ID_N',
UNIT_ID_N)[1]) = 1]">
<xsl:sort select="UNIT_ID_N"/>
<xsl:element name="ContainerGroup">
<xsl:attribute name="UNIT_ID_N">
<xsl:value-of select="UNIT_ID_N"/>
</xsl:attribute>
<xsl:for-each select="key('DetailsByUNIT_ID_N', UNIT_ID_N)">
<xsl:element name="Container">
<xsl:copy-of select="*" />
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</GroupedContainers>
</xsl:template>
</xsl:stylesheet>
 
D

David Carlisle

<xsl:template match="Details">

That matches an element with local name Details and no namepace uri,
which doesn't match your source, change to


<xsl:template match="x:Details" xmlns:x="http://someuri">

then it will match.


<xsl:element name="ContainerGroup">
<xsl:attribute name="UNIT_ID_N">
<xsl:value-of select="UNIT_ID_N"/>
</xsl:attribute>
...
</xsl:element>

It would be simpler to write that as

<ContainerGroup UNIT_ID_N="{UNIT_ID_N}">
...
</ContainerGroup>

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top