0

XSLTを学んでいます。この投稿 @Rich のアドバイスに従って、ノードをノードに変換しようとしています。How to replace a node-name with another in Xslt?

ここに私の入力XMLがあります:

<ns:positionSkillResponse xmlns:ns="http://positionskillmanagementservice.webservices.com">
<ns:return>1</ns:return>
<ns:return>9</ns:return>
</ns:positionSkillResponse>

以下のコードで変換しようとしていますが、パーサー エラーが発生しています。ns:return が問題だと思います。これは、トランスフォーマー コードが名前空間 ns を解決する方法を認識していないためです。しかし、名前空間は URL に公開されていないため、そこに指定することはできません。それが問題ですか?私は何をしますか?

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

  <xsl:output method="xml" />

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

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

結果:

Error:XSLTProcessor::transformToXml() [<a href='xsltprocessor.transformtoxml'>xsltprocessor.transformtoxml</a>]: No stylesheet associated to this object

このツールによるテスト:

4

1 に答える 1

1

あなたの XSL は無効です (未完成の名前空間宣言があり、終了xsl:stylesheetタグがありません) が、これが修正されたとしても、そのツールは機能しないようです。代わりにこれを試してください:

http://www.xslfiddle.net/

この XSLT がそのツールで指定された入力とともに使用される場合:

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

  <xsl:output method="xml" />

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

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

生成される結果は次のとおりです。

<?xml version="1.0"?><ns:positionSkillResponse xmlns:ns="http://positionskillmanagementservice.webservices.com"><parameter>1</parameter><parameter>9</parameter></ns:positionSkillResponse>
于 2013-04-22T22:41:22.503 に答える