This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: namespaces and copying trees


Hi Joern,

> Now I want (among other things) to generate an HTML version of this
> file, without the metadata. How can I exclude everything in the
> "foo" namespace?

Use an identity template to copy everything:

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()" />
  </xsl:copy>
</xsl:template>

And then have another template that matches anything in the namespace
you want to exclude, and either does nothing at all:

<xsl:template match="foo:*|@foo:*" />

Or, if elements in this namespace can have other information that you
*do* want nested inside them, carries on processing the contents:

<xsl:template match="foo:*|@foo:*">
  <xsl:apply-templates />
</xsl:template>

If you care that the result will contain a namespace declaration for
the foo namespace, then you need to create the elements using
xsl:element instead:

<xsl:template match="*">
  <xsl:element name="{name()}" namespace="{namespace-uri()}">
    <xsl:apply-templates select="@*|node()" />
  </xsl:element>
</xsl:template>

You may need to play around with priorities so that the above template
for elements not in the foo namespace has a higher priority than the
identity template I gave at the beginning of the email, while
retaining a lower priority than the template for elements/attributes
in the foo namespace.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]