我正在将一个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