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>
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>