我的目标是过滤基于通知的属性匹配值。有一个xml作为参数输入'privileges'
如下
<privileges>
<privilege>Access my notices</privilege>
<privilege>Access draft notices</privilege>
<privilege>Place notice</privilege>
<privilege>Access published notices</privilege>
<privilege>Place notice of type:2903</privilege>
<privilege>Place notice of type:2413</privilege>
<privilege>Place notice of type:2803</privilege>
<privilege>Access pending notices</privilege>
<privilege>Access my account</privilege>
<privilege>Place legacy notice</privilege>
<privilege>Access my searches</privilege>
</privileges>
在这里,有一些数字[它表示通知ID],例如2413, 2803
等。
我的 xml 输入是
<notice-taxonomy>
<notice-type code="11" level="category" name="State" popular="true" service-key="all-notices" sort="01">
<notice-type code="1101" level="notice" name="Proclamations" sort="01"/>
<notice-type code="2803" level="notice" name="Royal Family" sort="02"/>
<notice-type code="1103" level="notice" name="Appointments to the Royal Household" sort="03"/>
<notice-type code="1104" level="notice" name="Loyal Addresses" sort="04"/>
<notice-type code="2413" level="notice" name="Honours and Awards" sort="05"/>
<notice-type code="1106" level="notice" name="Privy Council Office" sort="06"/>
<notice-type code="2413" level="notice" name="Change of Name and/or Arms" sort="07"/>
<notice-type code="1108" level="notice" name="Crown Office" sort="08"/>
<notice-type code="1109" level="notice" name="Duchy of Cornwall or Duchy of Lancaster" sort="09"/>
</notice-taxonomy>
我的 xslt 是
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:param name="privileges" as="node()" select="doc('privileges.xml')"/>
<xsl:variable name="codeps" select="substring-after($privileges//privilege, ':')"/>
<xsl:output encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="notice-taxonomy">
<notice-taxonomy>
<xsl:for-each-group select="notice-type" group-by="@code = $codeps">
<xsl:sequence select="." />
</xsl:for-each-group>
</notice-taxonomy>
</xsl:template>
</xsl:stylesheet>
任何code
属性与参数值匹配[即从preveliges
] 中提取的数字,那么,这些notice-type
s 只需要在输出中列出。
例如,如果它与 2803 匹配,则输出应该是
<notice-taxonomy>
<notice-type code="2803" level="notice" name="Royal Family" sort="02"/>
<notice-type code="2803" level="notice" name="Change of Name and/or Arms" sort="07"/>
</notice-taxonomy>
如果匹配2413
<notice-taxonomy>
<notice-type code="2413" level="notice" name="Royal Family" sort="02"/>
<notice-type code="2413" level="notice" name="Change of Name and/or Arms" sort="07"/>
</notice-taxonomy>
如果两者都匹配,
<notice-taxonomy>
<notice-type code="2803" level="notice" name="Royal Family" sort="02"/>
<notice-type code="2803" level="notice" name="Change of Name and/or Arms" sort="07"/>
<notice-type code="2413" level="notice" name="Crown Office" sort="08"/>
<notice-type code="1413" level="notice" name="Duchy of Cornwall or Duchy of Lancaster" sort="09"/>
</notice-taxonomy>
请给我一个想法。谢谢