我正在將一個XML文件轉換爲另一種XML格式。檢查節點是否存在於具有XSLT的文檔中
下面是示例源文件:
<xml>
<title>Pride and Prejudice</title>
<subtitle>Love Novel</subtitle>
</xml>
這裏是XSL文件:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<Product>
<xsl:apply-templates/>
</Product>
</xsl:template>
<xsl:template match="title">
<TitleDetail>
<TitleType>01</TitleType>
<TitleElement>
<TitleElementLevel>01</TitleElementLevel>
<TitleText><xsl:value-of select="current()"/></TitleText>
<!--Here Problem!!!-->
<xsl:if test="subtitle">
<Subtitle>123</Subtitle>
</xsl:if>
</TitleElement>
</TitleDetail>
</xsl:template>
想法是,如果源文件包含字幕標記我需要插入 「字幕」節點到「TitleDetail」,但是「if」條件返回false。如何檢查源文件是否有字幕信息?
感謝您的幫助。我嘗試了你的解決方案,但字幕標籤已被替換兩次:一個'Subtitle'是'TitleDetail'的後代,另一個是'Product'元素的後代。 「TitleDetail」中只需要一個'Subtitle'標籤。附: - 我使用這一行。 –
Tamara
@Tamara我已經添加了一些可能的方法來解決這個問題。 –
謝謝,它的工作原理。 – Tamara