代码之家  ›  专栏  ›  技术社区  ›  Walter Kuhn

XSLT1.0转换使用变量删除重复项

  •  0
  • Walter Kuhn  · 技术社区  · 6 年前

    出于几个原因,我需要在XSLT1.0中派生一个变量,该变量可以在转换过程中重用,该变量收集重复项的唯一列表。

    <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>
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   GSerg    6 年前
    <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"