我有一個XML,像這樣:XSLT變化值節點
<?xml version="1.0" encoding="UTF-8"?>
<earth>
<computer>
<parts>
<cpu>AMD;fast</cpu>
<video>GF</video>
<power>slow</power>
...others
</parts>
<owner>
<name>Frank</name>
<owner>
</computer>
<earth>
我想創建XSL轉換(XSL:樣式版本= 「2.0」 的xmlns:XSL =「HTTP ://www.w3.org/1999/XSL/Transform「)。我的預期結果只有當CPU有符號時';' - 在';'之後權力應該變爲價值,如果不存在';'結果應該沒有變化
<earth>
<computer>
<parts>
<cpu>AMD</cpu>
<video>GF</video>
<power>fast</power>
...others
</parts>
<owner>
<name>Frank</name>
<owner>
</computer>
<earth>
嘗試做這樣的事情,但沒有運氣:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/xpath-functions"
exclude-result-prefixes="fn">
<xsl:output encoding="utf-8" method="xml" indent="yes" />
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="parts">
<xsl:choose>
<!-- try test if node name equals 'power' if equals them try make logic
here, this dont work-->
<xsl:when test="name() = 'power'">
<xsl:variable name="text" select="./cpu" />
<xsl:variable name="sep" select="';'" />
<xsl:variable name="powerTable" select="tokenize($text, $sep)" />
<xsl:value-of select="$powerTable[1]" />
</xsl:when>
<!--if not 'power' copy node -->
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
*「我有一個XML樣式表」*。我們可以知道它是怎麼樣的?因爲發佈到目前爲止只是* XMLs * – har07
我編輯我的文章,我有xml文件,並需要創建xsl將此文件轉換爲新的xml文件,並獲得預期結果 – Wait
您是否試圖編寫XSLT到目前爲止?如果有,請分享並解釋哪部分不按預期工作,或者哪部分不知道如何實施。如果你還沒有,請閱讀關於XSLT的介紹性教程,並嘗試先自己編寫一個教程。祝你好運! – har07