xml - 基于输入值的 xsl 转换
问题描述
我需要我的 xml 输出,但是输出 xml 是基于来自输入值的条件。输出 xml 不是输入 xml 的转换。xml 在另一个由文档函数访问的变量中。在这里,我使用文档功能在xslt本身中使用了 xml 。
文档函数访问的xml具有 id 属性,其值按升序排列。输入是一个数字(例如来自输入 xml),该数字应与从顶部选择元素开始访问的 xml 文档的 id 属性进行比较。如果在任何情况下对应的值(id 属性 + 15)大于输入数字,则应从输出xml中忽略特定的选择元素和前面的选择元素。
例如,如果输入数字为 100,则输出应如下所示,因为满足条件的第一个元素是 id 值“90”。因为 90 +15 大于 100。
<menu>
<choice id="95">C</choice>
<choice id="100">C</choice>
</menu>
我的输入 xml 说
<a>100</a>
我的 xslt 输出一切
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:my="my:my">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<my:elements>
<menu>
<choice id="20">ABC</choice>
<choice id="23">B</choice>
<choice id="30">C</choice>
<choice id="37">C</choice>
<choice id="45">C</choice>
<choice id="50">C</choice>
<choice id="90">C</choice>
<choice id="95">C</choice>
<choice id="100">C</choice>
</menu>
</my:elements>
<xsl:template match="/">
<xsl:copy-of select="document('')/*/my:elements/*"/>
</xsl:template>
</xsl:stylesheet>
解决方案
这是一种方法。将其视为伪代码。您必须插入详细信息。
<!-- Find the id of the first choice that over the limit. -->
<xsl:variable name="firstChoiceOverLimitID" select="generate-id(document('')/*/my:elements//choice[number(@id) + 15 > 100][1])"/>
<xsl:template match="/">
<!-- Output everything after the first choice over the limit. -->
<xsl:copy-of select="document('')/*/my:elements//choice[generate-id(.) = $firstChoiceOverLimitID]/following-sibling::choice"/>
</xsl:template>
推荐阅读
- excel - 在 VBA Excel 中使用索引公式和名称的参考
- php - 如何打开位于我服务器上另一个目录中的 imgs 文件?
- java - 在休眠中动态添加查询字符串中的表名
- spring - 如何在转换(动作)Spring Webflow上清除表单
- tomcat - 从 weblogic 到 tomcat 的 adf 项目
- google-cloud-platform - 谷歌云平台存储优化的实例有哪些?
- android - 使用 new 关键字实例化 customview 对象时,不会调用 Android draw()
- android - 将系统属性与 proguard 配置文件一起传递给 gradle proguardFile 属性
- regex - 使用 Jmeter 测试 Web 应用程序时,正则表达式在执行动态 GUID 期间不起作用?任何人都可以帮助我吗?
- jsp - 如何在Struts2上创建包含xss的项目