1
我嘗試做以下的XSLT 1.0:每個在每個邏輯
複製所有的是爲輸出,其中的條件是弗拉姆元素的任何弗拉姆的屬性(@name和@type和@ref的)值與任何XFram元素相匹配,那麼它應該用XFram/text()更新Fram/text()。在複製剩餘的XFram元素之後(所有這些都符合上述條件)並將它們轉換爲Fram標記。
注意:第三個Fram元素的所有屬性都與第三個Xfram元素相匹配,因此在第三個Fram元素中添加了文本。其餘的XFarm元素轉換爲Fram元素並添加到最後的Fram元素之後。你也會注意到Fram的訂單沒有改變。
Input.xml中
<Doc>AL
<Frams>
<Fram type="x" name="Fram1" ref="ref1">This is Fram One</Fram>
<Fram type="y" name="Fram2" ref="ref2">This is Fram Two</Fram>
<Fram type="z" name="Fram3" ref="ref3">This is Fram Three</Fram>
<Fram type="a" name="Fram4" ref="ref3">This is Fram Four</Fram>
<Fram type="b" name="Fram5" ref="ref3">This is Fram Five</Fram>
</Frams>
<XFram>
<XFram type="e" name="XFram1" ref="Xref1">This is XFram One</Fram>
<XFram type="f" name="XFram2" ref="Xref2">This is XFram Two</Fram>
<XFram type="z" name="XFram3" ref="Xref3">This is XFram Three</Fram>
<XFram type="e" name="XFram1" ref="Xref1">This is XFram Four</Fram>
<XFram>
<Doc>
輸出應該是:
<Doc>
<Frams>
<Fram type="x" name="Fram1" ref="ref1">This is Fram One</Fram>
<Fram type="y" name="Fram2" ref="ref2">This is Fram Two</Fram>
<Fram type="z" name="Fram3" ref="ref3">This is XFram Three</Fram>
<Fram type="a" name="Fram4" ref="ref3">This is Fram Four</Fram>
<Fram type="b" name="Fram5" ref="ref3">This is Fram Five</Fram>
<XFram type="e" name="XFram1" ref="Xref1">This is XFram One</Fram>
<XFram type="f" name="XFram2" ref="Xref2">This is XFram Two</Fram>
<XFram type="e" name="XFram1" ref="Xref1">This is XFram Four</Fram>
</Frams>
<Doc>
我做這樣的事情,但沒能想到的邏輯:
<xsl:template match="/">
<xsl:for-each select="XFram">
<xsl:variable name="type">
<xsl:value-of select="type"/>
</xsl:variable>
<xsl:variable name="name">
<xsl:value-of select="name"/>
</xsl:variable>
<xsl:variable name="ref">
<xsl:value-of select="ref"/>
</xsl:variable>
<xsl:for-each select="//Fram">
<xsl:choose>
<xsl:when test="(type = $type) and (name = $name) and (ref = $ref)"> </xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</xsl:template>