xslt-1.0 - XSLT 1.0 转换使用变量删除重复项
问题描述
由于几个原因,我需要在 XSLT 1.0 中派生一个可以在转换期间重复使用的变量,它收集重复条目的唯一列表。
输入数据在 XSLT 中生成到变量“portlist”中:
<plist>
<p>12345</p>
<p>12345</p>
<p>9876</p>
<p>12345</p>
<plist>
在我的 XSLT 模板中,我需要一个变量“reducedList”在转换中重复使用多次。如何在 XSLT 中生成一个新变量“reducedList”,它看起来像
<plist>
<p>12345</p>
<p>9876</p>
<plist>
我找到了几个例子,但必须承认我无法弄清楚。
我的 xslt 模板看起来像
<xsl:template match="stage">
<xsl:variable name="portlist" > <!-- returns a sorted list of all ports -->
<plist>
<xsl:for-each select="provider/server/QMGR"><!-- input from XML -->
<xsl:sort select="."/>
<p><xsl:value-of select="./@port"/></p>
</xsl:for-each>
</plist>
</xsl:variable>
<!-- here i need to derive the new variable reducedList -->
<!-- more code using reducedList follows here -->
</xsl:template>
解决方案
<xsl:variable name="portlist">
<plist>
<p>12345</p>
<p>12345</p>
<p>9876</p>
<p>12345</p>
</plist>
</xsl:variable>
<xsl:variable name="reducedList">
<plist>
<xsl:copy-of select="ext:node-set($portlist)/plist/p[not(text() = preceding-sibling::p/text())]"/>
</plist>
</xsl:variable>
ext
您的扩展名称空间在哪里node-set()
,例如xmlns:ext="urn:schemas-microsoft-com:xslt"
.
推荐阅读
- html - 如何在垫卡中居中标题?
- javascript - 我正在尝试将子对象文字关联到父对象文字
- javascript - 是否可以获取暂停的 chrome 下载的下载数据?
- python - 使用字典将字符串打印为终端中的垂直横幅。Python3
- sql - 带有 LAG 的 SQL 更新
- python - 如何在 python 中处理非常大的文件(13GB)而不会崩溃?
- c++ - 我正在使用 Boost.Spirit 来使用 boost::tuple 来检索解析器的属性,但没有成功
- bash - 即使有引号,我的数组也不会将两个单词的元素作为一个元素读取?
- api - 免费新闻 API VIA GITHUB,如何在改造中实现此代码?
- python - 删除 Pandas DataFrame 中的正则表达式、方括号、单引号和双引号