2016-03-24 14 views
-1

私はこれを長らく試してきたので、どこでも答えを見つけることができないかもしれません。ルート要素に名前空間を持つXSLT

サイトマップを表すXMLファイルがあります。

<?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> 
      ... 

このXMLはサイトマップを表します。私はこれを階層的なリストにするためにXSLTを書いています。

<?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> 

私は<urlset xmlns="..>を持っている場合は、このスタイルシートは動作しませんが、私は(属性なし)だけ<xmlns>を使用するようにノードを変更した場合、それは動作します。

私はXSLTの教祖から遠いです。誰でも提案がありますか?

+0

これは、よくある質問です。* namespace *を検索してください。 –

+0

あなたの質問のタイトルをSO検索ボックスに入力すると、ほぼ同じ質問に対して125件のヒットが得られます。どのようにそれらを見つけるのに失敗することができますか? –

答えて

0

見つけました。私はXSLTにこれを追加しましたが、明らかにそのコピーを作成しますが、名前空間は削除されます。

<!-- 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> 
+0

代わりに、(例えば)http://stackoverflow.com/questions/34758492/xslt-transform-doesnt-work-until-i-remove-root-node/34762628#34762628が見つかりました。 –

関連する問題