【问题标题】:xsl transformation based on value from input基于输入值的 xsl 转换
【发布时间】:2021-02-04 09:47:37
【问题描述】:

我需要我的 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>

【问题讨论】:

    标签: xml xslt-1.0


    【解决方案1】:

    这是一种方法。将其视为伪代码。您必须插入详细信息。

    <!-- 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 &gt; 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>
    

    【讨论】:

      猜你喜欢
      • 2021-01-27
      • 2012-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多