Stumped on this XSLT

Discussion in 'XML' started by PBR, Oct 5, 2004.

  1. PBR

    PBR Guest

    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>
    PBR, Oct 5, 2004
    #1
    1. Advertising

  2. <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
    David Carlisle, Oct 5, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ville Walveranta

    Stumped with a CPAN/CPANPLUS failure

    Ville Walveranta, Oct 27, 2003, in forum: Perl
    Replies:
    1
    Views:
    625
    Ville Walveranta
    Nov 7, 2003
  2. Joe Ross

    General Network Error - MS Stumped

    Joe Ross, Feb 26, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    550
    Joe Ross
    Mar 1, 2004
  3. shland

    Stumped...

    shland, May 5, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    418
    Ashish M Bhonkiya
    May 5, 2004
  4. Replies:
    2
    Views:
    459
    David Carlisle
    Feb 1, 2005
  5. J
    Replies:
    4
    Views:
    374
Loading...

Share This Page