我正在尝试从这个XML中获取type = city的唯一位置数量,但不知道如何执行此操作..我一直在尝试应用计数,但这不匹配,我会需要匹配一个唯一的名称以及
<root>
<report>
<location name="Amsterdam" type="City">
<amtPeople>1 Million+</amtPeople>
<date>21-12-2017</date>
</location>
<location name="London" type="City">
<amtPeople>1 Million+</amtPeople>
<date>21-12-2017</date>
</location>
<location name="Boekelo" type="Village">
<amtPeople>1 Million+</amtPeople>
<date>21-12-2017</date>
</location>
</report>
<report>
<location name="Amsterdam" type="City">
<amtPeople>1 Million+</amtPeople>
<date>14-12-2017</date>
</location>
<location name="New York" type="City">
<amtPeople>1 Million+</amtPeople>
<date>14-12-2017</date>
</location>
<location name="Capelle" type="Village">
<amtPeople>1 Million+</amtPeople>
<date>14-12-2017</date>
</location>
</report>
</root>
XSLT
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="Log"/>
<xsl:variable name="AllCities" select="count($Log/root/report/location[@type='City'])"/>
<xsl:template match="/">
<amtCities><xsl:value-of select="$AllCities"/></amtCities>
</xsl:template>
</xsl:stylesheet>
基于XML示例的预期输出:
<amtCities>3</amtCities>
答案 0 :(得分:2)
使用不同值的计数:
import { CoursesComponent } from './Courses.Component';
答案 1 :(得分:0)
/root/report/location[@type='City']
。答案 2 :(得分:0)
我用手动分配参数值,其工作正常:
<xsl:param name="Log" select="doc('File.xml')"/>
<xsl:variable name="AllCities" select="count($Log/root/report/location[@type='City'])"/>
<xsl:template match="/">
<amtCities><xsl:value-of select="$AllCities"/></amtCities>
</xsl:template>
我正在使用氧气进行转换和SAXON-PE-9.6.0.7。
答案 3 :(得分:0)
<xsl:param name="Log" select="doc('File.xml')"/>
<xsl:template match="/">
<amtcities>
<xsl:value-of select="count(distinct-values($Log/root/report/location[@type='City']/@name))"/>
</amtcities>
</xsl:template>