xslt - 如何计数()属性中与另一个不在同一lv中的元素?
问题描述
尽管我已经尝试了很多方法来编写这些 count() 行,但我无法让我的 Xslt 表正常工作。
在查看我的尝试之前,请查看下面的代码。我试过了:(1)
<xsl:for-each select="Trans/Episode/Section/Turn/tour">
<tr>
<td><xsl:value-of select="count(motBDL[@lexeme='JE'])" /></td>
</tr>
</xsl:for-each>
(2)
<td><xsl:value-of select="count(motBDL[lexeme='JE'])" /></td>
(3)
<xsl:for-each select="Trans">
<td><xsl:value-of select="count(/Episode/Section/Turn/tour/motBDL[@lexeme='JE'])" /></td>
(4)`
与 (5;6;7;8)"()" 而不是 "[]" 相同
XML =
<!--The entire code is correct (just for you to understand what I am trying to extract)-->
<?xml version="1.0" encoding="UTF8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="Projet-Info.xsl"?>
<!DOCTYPE Trans SYSTEM "trans-corpus.dtd">
<Trans scribe="computer-name" audio_filename="Debat Hollande Sarkozy 1998" video_filename="" version="8" version_date="181221">
<Speakers>
<Speaker name="Nicolas Sarkozy" check="yes"/>
<Speaker name="François Hollande" check="yes"/>
<Speaker name="Journaliste" check="no"/>
<Speaker name="Journaliste 2" check="no"/>
</Speakers>
<Episode>
<Section type="report" startTime="0" endTime="1408.652">
<Sync time="0.152"/>
<Turn speaker="spk1" startTime="0.152" endTime="3.038">
<tour nbmots="6" id="000000">
<motBDL lexeme="POUR" phon="puʁ">pour</motBDL>
<motBDL lexeme="MOI" phon="mwa">moi</motBDL>
<motBDL lexeme="JE" phon="ʒə">je</motBDL>
<motBDL lexeme="NE" phon="nə">ne</motBDL>
<motBDL lexeme="SAVOIR" phon="save">savais</motBDL>
<motBDL lexeme="PAS" phon="pa">pas</motBDL>
</tour>
</Turn>
</Section>
</Episode>
</Trans>
XSL =
<!--Code b4 is correct-->
<table border="2" style="text-align: center;">
<tr>
<!--<th>nom</th>-->
<th>je</th>
</tr>
<xsl:for-each select="Trans">
<xsl:if test="not(@check='no')">
<tr>
<td><xsl:value-of select="Speakers/Speaker/@name" /></td>
<td><xsl:value-of select="count(Episode/Section/Turn/tour/motBDL[@lexeme='JE'])" /></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
<!--Code after is correct-->
<!--I expect when I run my program on firefox to actually run.-->
解决方案
你已经用一个正斜杠开始你的表达......
/Episode/Section/Turn/tour/motBDL[@lexeme='JE']
这意味着 xpath 表达式将相对于文档节点,而不是相对于您当前所在的节点。你应该做这个...
<xsl:value-of select="count(Episode/Section/Turn/tour/motBDL[@lexeme='JE'])" />
你也有这个陈述同样的问题
<xsl:value-of select="/Speakers/Speaker/@nom" />
这也是指一个不存在的属性。如果您打算在@name
这里写,请记住在 XSLT 1.0 中,如果您这样做xsl:value-of
并选择多个节点,那么只会输出第一个节点。
另外,请注意,您的 XSLT 中有两个?xml-stylesheet
指令。我不确定这是允许的......
推荐阅读
- c# - 停止计时器后读取用户输入?
- java - @RequestParam 不同的 URI
- java - 在列表视图中解析 Json 并将点击监听器添加到每个列表项
- python - 查找给定列表的模式和第二模式
- php - PHP parsing json failing
- mqtt - How is the Sparkplug is_historical metric property used?
- html - 固定背景附件的问题
- tvos - UIUserInterfaceStyle 在每次重新打开时恢复为 UIUserInterfaceStyleDark
- r - generate a special matrix (max value of column sum is minimum) with given number of column from a vector
- c# - swagger 4.0 Asp.net core 2.2 需要的body参数