我試圖使用像過濾器自帶的XML參數列在XSL領域獲得從XML數據的數據值的: 參數是這樣一個xml:動態的xsl:使用從參數
<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",
}
]
}
謝謝!
你能否進一步解釋你的解決方案? – Dev
除非你告訴我你不瞭解哪一部分。 –