私はXSLが初めてです。XSL ファイルを使用して XML 要素の値を読み取ろうとしています。私のXMLファイルは次のようなものです:
<PersonList>
<Person>
<Name>person1</Name>
<Age>21</Age>
</Person>
<Person>
<Name>person2</Name>
<Age>21</Age>
</Person>
</PersonList>
私のXSLファイルは次のようなものです:
<xsl:stylesheet version="1.0" xmlns=...>
<xsl:output method="xml" indent="yes" encoding="utf-8" omit-xml declaration="no" />
<xsl template match="/">
<PersonList>
<xsl:for-each select="PersonList/Person">
<Person>
<xsl:for-each select="*">
<xsl:variable name="elementName">
<xsl:value-of select="name(.)" />
</xsl:variable>
<xsl:variable name="elementValue">
???
</xsl:variable>
</xsl:for-each>
</Person>
</xsl:for-each>
</PersonList>
</xsl:template>
</xsl:stylesheet>
変数???
に格納されている要素の値を取得するには、どのように置き換える必要がありますか。elementName
次の3行を別々に試しました:
<xsl:value-of select="value(.)" />
<xsl:value-of select="value($elementName)" />
<xsl:value-of select="$elementName" />
しかし運がない。助けてください!