XSL の XML パラメータにリストされているフィールドをフィルターするのと同じように使用して、XML からデータを取得しようとしています: パラメータは次のような xml です:
<Catalog name="Catalog1">
<Fields>
<Field>ID</Field>
<Field>Name</Field>
<Field>Description</Field>
</Fields>
</Catalog>
したがって、次のような別の XML からこの要素を取得する必要があります。
<?xml version="1.0" encoding="UTF-8"?>
<Nodes>
<Node>
<Data>
<Attribute name="ID">Desktop</Attribute>
<Attribute name="Parent">administrator</Attribute>
<Attribute name="Name">Desktop</Attribute>
<Attribute name="Description">Desktop folder</Attribute>
</Data>
<Relationship>
<RelatedNodes>
<Node>
<Data>
<Attribute name="ID">administrator</Attribute>
<Attribute name="Parent"></Attribute>
<Attribute name="Name">administrator</Attribute>
<Attribute name="Description">administrator folder</Attribute>
</Data>
</Node>
</RelatedNodes>
</Relationship>
</Node>
</Nodes>
これまでのところ、次のような XSL テンプレートがあります。
<?xml version="1.0"?>
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' >
<xsl:output method='text' encoding="UTF-8"/>
<xsl:param name="Fields"> <!--type="xml"--></xsl:param>
<xsl:template match="/">
{
<xsl:apply-templates select="//Data[Attribute[@name='Parent']='' ]/parent::Node" />
}
</xsl:template>
<xsl:template match="Node" >
"children":[
{
<xsl:for-each select="$Fields/Catalog/Fields/Field">
<xsl:variable name="AttributeName" select="." />
"<xsl:value-of select="$AttributeName"/>": " <xsl:value-of select="Data/Attribute[@name=$AttributeName]" /> ",
</xsl:for-each>
<xsl:apply-templates select="ancestor::Node[1]"/>
}
]
</xsl:template>
</xsl:stylesheet>
しかし、機能していません。xpath が値を取得していません。これは、xpath のフィルターに「'」文字を設定する必要があるためだと思います。そのため、concat を使用していましたが、concat は xpath を文字列, 何かアイデアはありますか?, 結果は次のようになります:
{
"children":[
{
"ID": "1",
"Name": "Name1",
"Description: "Desc1",
}
]
}
ありがとう!