我有一个非常大的 xml,其中一个块不断重复。现在我只想要第一个块的标签名称。我的 xsl 很差。我试过但徒劳无功。请任何人帮助。我的 xml 如下所示,
<catalog>
<product>
<title>GATE MCQ For Electronics & Communication Engineering</title>
<originalprice>Rs 680</originalprice>
<sellingprice>Rs 680Rs 530</sellingprice>
<discount>22% Off</discount>
<payment>Cash on delivery available</payment>
<review/>
</product>
<product>
<title>Gate Guide Computer Science / Information Technology (with CD)</title>
<originalprice>Rs 695</originalprice>
<sellingprice>Rs 695Rs 480</sellingprice>
<discount>31% Off</discount>
<payment>Cash on delivery available</payment>
<review/>
</product>
产品块不断重复但具有不同的值。我现在使用的 xsl 是,
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.java2s.com"
xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="//*[local-name() = 'product'][1]/*">
<xsl:value-of select="name()"/>
</xsl:template>
</xsl:stylesheet>
得到的输出是,
title
originalprice
sellingprice
discount
payment
review
Gate Guide Computer Science / Information Technology (with CD)
Rs 695
Rs 695Rs 480
31% Off
Cash on delivery available
但所需的输出是,
title
originalprice
sellingprice
discount
payment
review
谢谢你。