1

それが可能かどうかはわかりませんが、ここにあります。

この XML から:

<?xml version="1.0" encoding="UTF-8"?>
<AttributesCollection>
    <Attributes>
        <AttributeName>AAA</AttributeName>
        <AttributeValue>Value1</AttributeValue>
    </Attributes>
    <Attributes>
        <AttributeName>BBB</AttributeName>
        <AttributeValue>Value2</AttributeValue>
    </Attributes>
</AttributesCollection>

XSL変換を使用して次のように変換しようとしています:

<Attributes>
   <AAA>Value1</AAA>
   <BBB>Value2</BBB>
</Attributes>

属性名は取得できますが、XML の作成方法がわかりません。これが私が試したものです。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <xsl:for-each select="./AttributesCollection/Attributes/AttributeName">
            Name:<xsl:value-of select="."/>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

私に与える:

<?xml version="1.0" encoding="UTF-8"?>
            Name:AAA
            Name:BBB

それで、私が探していることをすることは可能ですか?何か助けはありますか?ありがとう

4

1 に答える 1

1

これはそれを行う必要があります:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/*">
    <Attributes>
      <xsl:apply-templates select="Attributes" />
    </Attributes>
  </xsl:template>

  <xsl:template match="Attributes">
    <xsl:element name="{AttributeName}">
      <xsl:value-of select="AttributeValue" />
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>

サンプル データで実行すると、結果は次のようになります。

<Attributes>
  <AAA>Value1</AAA>
  <BBB>Value2</BBB>
</Attributes>
于 2013-08-12T15:21:20.487 に答える