我有一个xml,如:
<EnhancedData>
<EmailAddress>abc.def@email.com</EmailAddress>
<PassengerName>ABC/DEF</PassengerName>
<RecordLocator_PNR>ABCDEF</RecordLocator_PNR>
</EnhancedData>
我正在使用的相应XSLT如下:
<xsl:for-each select="EnhancedData">
<xsl:if test="*">
<EnhancedData>
<xsl:value-of select="Y" />
</EnhancedData>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="EnhancedData/EmailAddress">
<EmailAddress>
<xsl:value-of select="." />
</EmailAddress>
</xsl:for-each>
<xsl:for-each select="EnhancedData/PassengerName">
<PassengerName>
<xsl:value-of select="." />
</PassengerName>
</xsl:for-each>
<xsl:for-each select="EnhancedData/RecordLocator_PNR">
<RecordLocator_PNR>
<xsl:value-of select="." />
</RecordLocator_PNR>
</xsl:for-each>
我正在使用Java代码,它使用XSLT将xml转换为另一个o / p文件。如果它包含任何子节点,我需要将增强数据设为Y.
使用当前代码,输出xml如下所示:
<EnhancedData/>
<EmailAddress>abc.def@email.com</EmailAddress>
<PassengerName>ABC/DEF</PassengerName>
<RecordLocator_PNR>ABCDEF</RecordLocator_PNR>
我需要的是:
<EnhancedData>Y</EnhancedData>
<EmailAddress>abc.def@email.com</EmailAddress>
<PassengerName>ABC/DEF</PassengerName>
<RecordLocator_PNR>ABCDEF</RecordLocator_PNR>
答案 0 :(得分:0)
而不是
<xsl:value-of select="Y" />
只需使用
<xsl:text>Y</xsl:text>