我有以下xml:
<t>
<property>value1</property>
<property type="oldtype">value2</property>
<property type="oldtype">value3</property>
<property type="oldtype">value4</property>
</t>
我想用 XSLT 設定第二個屬性元素的型別屬性。
目前我有以下 XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="pNewType" select="'newtype'"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="property[2]/@type">
<xsl:attribute name="type">
<xsl:value-of select="$pNewType"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
它適用于 xsltproc 和在線 xslt 工具,但不適用于 Qt 的 XSLT 實作。這是進行這種轉變的正確方法嗎?
Qt的isValid()校驗函式回傳true,但是轉換的結果和輸入一??樣。
預期的輸出是:
<t>
<property>value1</property>
<property type="newtype">value2</property>
<property type="oldtype">value3</property>
<property type="oldtype">value4</property>
</t>
(沒有“索引” [2],它按預期作業,更改所有屬性)
uj5u.com熱心網友回復:
是的,這應該可以作業,并且必須是 QT 的 XSLT 實作中的一個錯誤。
您可能想嘗試在語意上等效但在語法上不同的東西,以查看是否可以解決該錯誤。
match 運算式實際上只是以下的簡寫:
property[position()=2]/@type
如果這不起作用,您可以嘗試:
property[count(preceding-sibling::property)=1]/@type
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/533236.html
標籤:xmlqtxslt
