2009-08-23 6 views
4

私は変換を使ってxml文書のルート要素に関する情報のリストを取得しようとしています。私が理解できない部分は次のとおりです。xsl/xpathでxmlnsを見つける

デフォルトの名前空間URLはどのようにして取得できますか?

すべてのxmlnsプレフィックスと関連するURLのリストを取得するにはどうすればよいですか?ここで

は私のxmlファイルです:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output 
    doctype-public="-//W3C//DTD XHTML 1.1//EN" 
    doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" 
    encoding="UTF-8" 
    indent="yes" 
    method="xml" 
    omit-xml-declaration="no" 
    version="1.0" /> 

    <xsl:template match="/"> 
     <html xmlns="http://www.w3.org/1999/xhtml"> 
      <head> 
       <title></title> 
      </head> 
      <body> 
       default namespace - <b>???</b><br /> 
       full tag name - <b><xsl:value-of select="name(*)"/></b><br /> 
       xmlns for tag - <b><xsl:value-of select="namespace-uri(*)"/></b><br /> 
       tag prefix - <b>???</b><br /> 
       tag name - <b><xsl:value-of select="local-name(*)"/></b><br /> 
       List of xmlns - <br /> 
       ???? 
      </body> 
     </html> 
</xsl:template> 

この変換は、ブラウザで行われている:

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" href="/example.xsl"?> 
<foo:mytag xmlns="http://default.example.com/" 
      xmlns:foo="http://foo.example.com/" 
      xmlns:bar="http://bar.example.com"> 
</foo:mytag> 

そして、ここでは私のXSLファイルです。基本的に私が結果として期待しているもの:

default namespace - http://default.example.com/ 
full tag name - foo:mytag 
xmlns for tag - http://foo.example.com/ 
tag prefix - foo 
tag name - mytag 
List of xmlns - 
     - http://default.example.com/ 
    foo - http://foo.example.com/ 
    bar - http://bar.example.com/ 

欠けているデータを記入するのに何か明白なものがありませんか?

+0

達成しようとしていることは何ですか?ネームスペース宣言のリストを必要とするよりも、ノードに関連付けられたネームスペースを知りたい方がもっと普通です。 –

答えて

5

これはほぼあなたが望むものだと思います。 XSLT 1.0 - XMLSpyでテスト済み

<xsl:template match="/"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
     <head> 
      <title></title> 
     </head> 
     <body> 
      default namespace - <b><xsl:value-of select="*/namespace::*[not (name())]"/></b><br /> 
      full tag name - <b><xsl:value-of select="name(*)"/></b><br /> 
      xmlns for tag - <b><xsl:value-of select="namespace-uri(*)"/></b><br /> 
      tag prefix - <b><xsl:value-of select="substring-before(name(*),':')" /></b><br /> 
      tag name - <b><xsl:value-of select="local-name(*)"/></b><br /> 
      List of xmlns - <br /> 
      <xsl:for-each select="*/namespace::*"> 
       <xsl:if test="not (name() = 'xml')"><xsl:text> 
        </xsl:text> 
        <xsl:value-of select="name()" /><xsl:text> - </xsl:text><xsl:value-of select="." /><br /> 
       </xsl:if> 
      </xsl:for-each> 
     </body> 
    </html> 
</xsl:template>