XSL1.0:在重复中选择特定元素



使用这样的XML:

<categories>
<request type="this request is B and O">
<list name="B"/>
<list name="O"/>
</request>  
<request type="this request is N only">
<list name="N"/>
</request>
<request type="this request is O and E">
<list name="O"/>
<list name="E"/>
</request>
<request type="this request is O and G">
<list name="O"/>
<list name="G"/>
</request>
<request type="this request is N and E">
<list name="N"/>
<list name="E"/>
</request>
<request type="this request is E only">
<list name="E"/>
</request>
<request type="this request is B only">
<list name="B"/>
</request>
<request type="this request is B and N">
<list name="N"/>
<list name="B"/>
</request>
</categories>

我试了如下:

<xsl:template name="simplified">
<xsl:for-each select="categories/request[child::list/@name = 'B'] | categories/request[child::list/@name = 'O'] | categories/request[child::list/@name = 'N']">
<fo:block>
<xsl:value-of select="@type"/>
</fo:block>
</xsl:for-each>
</xsl:template>

规则是:

  • 在所有请求后重复,其中其子类型为将只使用名称B、O或N;
  • 如果有<请求>元素有一个带有@name "B"以及一个带有@name "O"或"N",应重复添加;
  • 如果有<请求>元素有一个带有@name "N"或"0",而是前一个或下一个列表元素(在相同的下)有@name "G"或"E",不应重复添加。

现在我收到以下结果:

this request is B and O
this request is N only
this request is O and E
this request is O and G
this request is N and E
this request is B only
this request is B and N

我需要收到以下正确的结果:

this request is B and O
this request is N only
this request is B only
this request is B and N

我如何更新我的重复模板为xsl1.0?

我很难理解你的描述。看来你想这样做:

XSLT 1.0

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="/categories">
<xsl:for-each select="request[not(list[contains('GE', @name)])]">
<xsl:value-of select="@type"/>
<xsl:text>&#10;</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

或-如果您更喜欢白名单而不是黑名单:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="/categories">
<xsl:for-each select="request[not(list[not(contains('BON', @name))])]">
<xsl:value-of select="@type"/>
<xsl:text>&#10;</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

相关内容

  • 没有找到相关文章

最新更新