0
我試圖根據它的值選擇應用哪種轉換。 如果測試是高清晰度,高清晰度將被刪除,只留下HD,但如果測試是標準,則只有SD將是設定值。選擇並轉換標記的值
源XML
<?xml version="1.0" encoding="UTF-8"?>
<file_information>
<asset_data>
<upn>FF074172</upn>
<title>test</title>
<version>High Definition</version>
<duration>00:30</duration>
<tc_in>23:00:00:00</tc_in>
<tc_out>23:00:30:00</tc_out>
<aspect_ratio>16X9</aspect_ratio>
<segment>
<sequence>1</sequence>
<tc_in>23:00:00:00</tc_in>
<tc_out>23:00:30:00</tc_out>
<comment></comment>
</segment>
</asset_data>
</file_information>
變換
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<file_information>
<asset_data>
<upn>
<xsl:value-of select="//upn"/>
</upn>
<title>
<xsl:value-of select="//title"/>
</title>
<xsl:choose>
<xsl:when test="High Definition">
<version>
<xsl:value-of select="translate(//version,'igh efinition','')"/>
</version>
</xsl:when>
<xsl:otherwise>
<version>
<xsl:value-of select="translate(//version,'tandard','D',)"/>
</version>
</xsl:otherwise>
</xsl:choose>
<duration>
<xsl:value-of select="//duration"/>
</duration>
<tc_in>
<xsl:value-of select="//tc_in"/>
</tc_in>
<tc_out>
<xsl:value-of select="//tc_out"/>
</tc_out>
<aspect_ratio>
<xsl:value-of select="translate(//aspect_ratio,'X',':')"/>
</aspect_ratio>
</asset_data>
</file_information>
期望輸出
<?xml version="1.0" encoding="UTF-8"?>
<file_information>
<asset_data>
<upn>FF074172</upn>
<title>test</title>
<version>HD</version>
<duration>00:30</duration>
<tc_in>23:00:00:00</tc_in>
<tc_out>23:00:30:00</tc_out>
<aspect_ratio>16:9</aspect_ratio>
<segment>
<sequence>1</sequence>
<tc_in>23:00:00:00</tc_in>
<tc_out>23:00:30:00</tc_out>
<comment></comment>
</segment>
</asset_data>
</file_information>
或
<?xml version="1.0" encoding="UTF-8"?>
<file_information>
<asset_data>
<upn>FF074172</upn>
<title>test</title>
<version>SD</version>
<duration>00:30</duration>
<tc_in>23:00:00:00</tc_in>
<tc_out>23:00:30:00</tc_out>
<aspect_ratio>16:9</aspect_ratio>
<segment>
<sequence>1</sequence>
<tc_in>23:00:00:00</tc_in>
<tc_out>23:00:30:00</tc_out>
<comment></comment>
</segment>
</asset_data>
</file_information>
你知道發生了什麼問題嗎? 謝謝
正因爲如此,這是一個XSLT 2.0答案(即使版本設置爲1.0)。 – 2014-10-27 16:20:07
更改 to and 到 (逗號在'D'移除後) –
2014-10-27 16:56:44