-1

I've been tinkering with this for too long and can't seem to find the answer anywhere -- or perhaps I don't know how to word the questions.

I have an XML file that represents a sitemap.

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   <url>
      <loc>http://...</loc>
      <pagetitle>English</pagetitle>
      <children>
         <url>
            <loc>http://...</loc>
            <pagetitle>page title</pagetitle>
         </url>
         <children>
            ...

This XML represents a site map. I have written an XSLT to turn this into a hierarchical list.

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="html" indent="yes" version="4.0"/>

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

    <xsl:template match="url">
        <li><a href="{loc}"><xsl:value-of select="pagetitle"/></a></li>
        <xsl:apply-templates select="children"/>
    </xsl:template>

    <xsl:template match="children">
        <ul><xsl:apply-templates select="url"/></ul>
    </xsl:template>

</xsl:stylesheet>

This style sheet doesn't work when I have <urlset xmlns="..>, but if I change the node to use just <xmlns> (without the attribute) it works.

I am far from an XSLT guru. Anyone have a suggestion?

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
jardineworks
  • 13
  • 1
  • 8

1 Answers1

0

Found it. I just added this to my XSLT which apparently makes a copy of it but strips namespaces.

  <!-- by default, copy all nodes -->
    <xsl:template match="*" mode="copy-no-namespaces">
        <xsl:element name="{local-name()}">
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()" mode="copy-no-namespaces"/>
        </xsl:element>
    </xsl:template>
jardineworks
  • 13
  • 1
  • 8
  • You should have found: http://stackoverflow.com/questions/34758492/xslt-transform-doesnt-work-until-i-remove-root-node/34762628#34762628 (for example) instead. – michael.hor257k Mar 24 '16 at 18:57