我是xsl的新手。 我需要编写一个 xslt 代码来转换下面的 xml 代码 如果我的"LongCallService"标签计数超过 2,那么 我需要选择这个第一个"LongCallService"标签并检查天气,它是否在"chargeGroup"中包含"inviceCode"子子元素标签!如果是,则需要显示。请帮忙。
XML代码:
<RelatedCharges>
<CVOIP>
//other child element</<CVOIP>>
<Internet>
//other child element</Internet>
<LongCallService>
<chargeGroup>
<InvoiceCode>some number</InvoiceCode>
</chargeGroup>
</LongCallService>
<LongCallService>
//other child element(child Structure same as above first sibling)</LongCallService>
<LongCallService>
//other child element(child Structure same as above first sibling)</LongCallService>
</RelatedCharges>
根据您的描述,我创建了一个XML文件,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<RelatedCharges>
<CVOIP> //other child element</CVOIP>
<Internet>//other child element</Internet>
<LongCallService>
<chargeGroup>
<Code></Code>
</chargeGroup>
<InvoiceCode>some number</InvoiceCode>
</LongCallService>
<LongCallService>//other child element</LongCallService>
<LongCallService>//other child element</LongCallService>
</RelatedCharges>
应用此样式表时:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:if test="count(RelatedCharges/LongCallService) > 2">
<xsl:copy-of select="RelatedCharges/LongCallService[1][chargeGroup/InvoiceCode]"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
它不输出任何内容,但如果第一个<LongCallService>
如下所示:
<LongCallService>
<chargeGroup>
<Code></Code>
<InvoiceCode>some number</InvoiceCode>
</chargeGroup>
</LongCallService>
它输出:
<?xml version="1.0" encoding="UTF-8"?>
<LongCallService>
<chargeGroup>
<Code/>
<InvoiceCode>some number</InvoiceCode>
</chargeGroup>
</LongCallService>