Xml XSLT-属性的出现
我有以下xml:Xml XSLT-属性的出现,xml,xslt,xpath,Xml,Xslt,Xpath,我有以下xml: <Books> <Book author="John" country="Norway"/> <Book author="Paul" /> <Book author="Steve" country="England"/> </Books> <Books> <Book author="George" /> <Book autho
<Books>
<Book author="John" country="Norway"/>
<Book author="Paul" />
<Book author="Steve" country="England"/>
</Books>
<Books>
<Book author="George" />
<Book author="Thomas" country="Germany"/>
</Books>
我想找到属性country在每个Books元素中的位置
<Books>
<Book author="John" country="Norway"/> --1
<Book author="Paul" />
<Book author="Steve" country="England"/> --2
<Book author="Bob" country="Denmark"/> --3
</Books>
<Books>
<Book author="George" />
<Book author="Thomas" country="Germany"/> --1
</Books>
我们可以使用哪个XPath函数进行此操作?您可以使用XPath count函数:
count(/Books/Book/@country)
您可以使用XPath计数函数:
count(/Books/Book/@country)
您可以计算具有该属性的前面同级的数量,以下是显示以下内容的模板:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Books/Book[@country]">
<xsl:value-of select="count(preceding-sibling::Book[@country]) + 1"/>
</xsl:template>
</xsl:stylesheet>
您可以计算具有该属性的前面同级的数量,以下是显示以下内容的模板:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Books/Book[@country]">
<xsl:value-of select="count(preceding-sibling::Book[@country]) + 1"/>
</xsl:template>
</xsl:stylesheet>
count返回国家/地区的事件总数。我想知道这个属性的位置。@saravana_pc-count是一个汇总函数。无法使用摘要函数检索位置。@Suresh-我同意不能使用计数。因此我想知道如何解决这个问题。@saravana_pc抱歉,我误解了你的问题。马丁的回答是我也会这么做。@saravana_pc-你想得到这个职位的图书元素的哪个国家属性?您输入的xml有多个国家/地区。如果您也想获得该职位,请用您希望看到的输出类型的详细信息更新您的问题。count返回国家/地区出现的总次数。我想知道这个属性的位置。@saravana_pc-count是一个汇总函数。无法使用摘要函数检索位置。@Suresh-我同意不能使用计数。因此我想知道如何解决这个问题。@saravana_pc抱歉,我误解了你的问题。马丁的回答是我也会这么做。@saravana_pc-你想得到这个职位的图书元素的哪个国家属性?您输入的xml有多个国家/地区。如果你也想得到这个职位,请用你希望看到的输出类型的细节更新你的问题。
1
2
3
1