Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: how to get unique set of node names

From: "Marrow" <m--a-r-r-o-w@--------------------.--->
To: NULL
Date: 8/5/2004 2:44:00 PM
Hi Daniel,

Using Muenchian technique something like this...

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="kDistinctElementNames" match="foo/*" use="local-name()"/>

<xsl:template match="/">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="foo">
  <xsl:copy>
    <xsl:for-each select="*[generate-id() =
generate-id(key('kDistinctElementNames',local-name()))]">
      <xsl:copy/>
    </xsl:for-each>
  </xsl:copy>
</xsl:template>
</xsl:stylesheet>


Although I suspect that that isn't really what you are after?  Perhaps what
you are trying to do is build an output that has a summary structure
(excluding repetitions) of the input document?  For example, what would you
want the output for the following XML to look like?...

<?xml version="1.0"?>
<foo>
  <foo2/>
  <bar>
    <a/>
    <a/>
    <a/>
    <b i="1"/>
    <b i="1"/>
    <c x="x">
      <xxx a="1"/>
      <xxx a="2"/>
      <yyy b="1"/>
    </c>
    <c x="y">
      <xxx a="3"/>
      <yyy b="2"/>
    </c>
    <c x="z">
      <yyy b="3"/>
      <zzz c="1"/>
    </c>
  </bar>
</foo>

perhaps you are looking for an output something like?...

<?xml version="1.0"?>
<foo>
  <foo2/>
  <bar>
    <a/>
    <b/>
    <c>
      <xxx/>
      <yyy/>
      <zzz/>
    </c>
  </bar>
</foo>

If so, then this can be done - but gets pretty complex ;)  But do say if
that's the end goal - I may have something that does that or about that.

Cheers
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator





"Daniel" <softwareengineer98037@y...> wrote in message
news:%23yQwioNeEHA.1604@T......
> e.g. from:
> <foo>
>     <a/>
>     <a/>
>     <a/>
>     <b i="1"/>
>     <b i="1"/>
>     <c x="y">hello</c>
>     <c x="y">hello</c>
>     <c x="y">hello</c>
> </foo>
>
> I would like to get
>
> <foo>
>     <a/>
>     <b/>
>     <c/>
> </foo>
>
>




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent