xsl-list
[Top] [All Lists]

RE: Name space confusion

2003-10-30 20:47:38
Hugh wrote:
I am wanting to write stylesheets that can be used by xml files from a
variety of sources
I have trouble because the name space is not always specified by the
supplier.  I would like to be able to match on an element of 
known local
name, but from a, possibly undefined namespace.
...
Sample XSL
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:fo="http://www.w3.org/1999/XSL/Format";>

<xsl:template match="/">
      <xsl:element name="myNewRoot">
              <xsl:for-each select=".//CgPoints">
              <xsl:element name="SomeOtherThing">
                      <xsl:apply-templates select="."/>
                      </xsl:element>
              </xsl:for-each>
      </xsl:element>
</xsl:template>

<xsl:template match="CgPoints">
      <xsl:element name="myFirstLevelChild">
      </xsl:element>
</xsl:template>
</xsl:stylesheet>

The match pattern is relatively easy; do
  <xsl:template match="*[local-name() = 'CgPoints']">

I'm not sure what you want to do for namespaces in the output...
If you don't need a namespace, you can leave your stylesheet as-is.
If you want to copy the namespace of the input XML, you can do
something like

  <xsl:template match="*[local-name() = 'CgPoints']">
    <xsl:element name="myFirstLevelChild"
       namespace="{namespace-uri()}" />
  </xsl:template>

This will copy the namespace-uri from CgPoints in the input XML.

Hopefully you're not picky about what namespace prefix is used. :-)

Lars


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



<Prev in Thread] Current Thread [Next in Thread>