English 中文(简体)
XSL - 名单等同执行
原标题:XSL - List equivalent implementation

我要知道,我们是否在相当于 Java名单的XSL 2.0中拥有一些东西。 我要再次指出一个模板10次,并用我的名字通过一个投入变量。 在模板内,我要采取行动,如增列项目,从名单上删除项目,在清单内重复项目等。 我可以看到像顺序一样的顺序,但我不敢肯定的是,这种顺序可以用来补充、消除、激发等等。 请分享你的想法以落实这一点。

在以下答复的帮助下,我尝试使用顺序,我与辛迪加一起面对一些问题,如宣布一个空档。 我愿利用“前列”或“散列”职能,印刷顺序1 2 3 4 5 6 7 8 9 10。 请帮助我打上yn子。

  <xsl:stylesheet version="2.0" 
  xmlns:locator="http://ntr.lxnx.org"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
  <xsl:template match="/"> 
  <xsl:variable name="output">
  <xsl:call-template name="calculate-data"> 
                <xsl:with-param 
                    name="sequence" 
                    select=""/> 
                 <xsl:with-param 
                    name="count"  
                    select="1"/>
            </xsl:call-template> 
  </xsl:variable>
  <xsl:value-of select="output"></xsl:value-of>
  </xsl:template>  
  <xsl:variable name="main-root" as="document-node()" select="/"/>

  <xsl:template name="calculate-data">
<xsl:param name="sequence"/>
  <xsl:param name="count" select="0"/>
<xsl:if test="$count != 10">
                fn:insert-before($count as item()*,0 as xs:integer,$sequence as item()*)
                <xsl:call-template name="calculate-data"> 
                    <xsl:with-param 
                        name="sequence" 
                        select="$sequence"/> 
                     <xsl:with-param 
                        name="count"  
                        select="$count + 1"/>
                </xsl:call-template>              


</xsl:if> 
        </xsl:template>
        </xsl:stylesheet>
最佳回答

With the clarification that an instance of a sequence, as anything else in XPath/XSLT are immutable, the answer is positive:

  1. Iterating over a sequence:

    <xsl:for-each select="$seq">
     <!-- Whatever necessary code here -->
     <!-- . is the current item of the sequence-->
    </xsl:for-each>
    
  2. Add an item to a sequence (produces a new sequence that is the result of this operation):

       insert-before($target as item()*,
                     $position as xs:integer,
                     $inserts as item()*) as item()*
    

Summary: Returns a new sequence constructed from the value of $target with the value of $inserts inserted at the position specified by the value of $position. (The value of $target is not affected by the sequence construction.)

.3. Concatenation of two sequences (produces a new sequence that is the result of this operation):

   $seq1 , $seq2

..4. Remove an item from a sequence:

     remove($target as item()*, $position as xs:integer) as item()*

Summary: Returns a new sequence constructed from the value of $target with the item at the position specified by the value of $position removed

..5. Extract a subsequence from a sequence:

   subsequence($sourceSeq as item()*,
               $startingLoc as xs:double,
               $length as xs:double) **as item**()*

Summary: Returns the contiguous sequence of items in the value of $sourceSeq beginning at the position indicated by the value of $startingLoc and continuing for the number of items indicated by the value of $length.

<>standard XPath 2.0功能超过

Note: The only feature that the XPath 2.0 sequence doesn t have is "nestedness". A sequence is always "flat" and an item of a sequence cannot be a sequence itself. There are ways to simulate multi-level sequences -- for example, an item can be a node and its children nodes can be regarded as a nested sequence.

Update: Here is how these functions can be used conveniently to solve the OP s updated question:

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns:my="my:my" >

 <xsl:template match="/">
  <xsl:sequence select="my:populateSequence((), 1, 10)"/>
 </xsl:template>

 <xsl:function name="my:populateSequence" as="xs:integer*">
  <xsl:param name="pSeq" as="xs:integer*"/>
  <xsl:param name="pStart" as="xs:integer"/>
  <xsl:param name="pEnd" as="xs:integer"/>

  <xsl:sequence select=
   "if($pStart gt $pEnd)
      then $pSeq
      else my:populateSequence(($pSeq, $pStart), $pStart+1, $pEnd)
   "/>
 </xsl:function>
</xsl:stylesheet>

When this XSLT 2.0 transformation is applied on any XML document (not used), the wanted result is produced:

1 2 3 4 5 6 7 8 9 10
问题回答

暂无回答




相关问题
When test hanging in an infinite loop

I m tokenising a string with XSLT 1.0 and trying to prevent empty strings from being recognised as tokens. Here s the entire function, based on XSLT Cookbook: <xsl:template name="tokenize"> ...

quick xslt for-each question

Let s say I have an XML document that has this: <keywords> <keyword>test</keyword> <keyword>test2</keyword> <keyword>test3</keyword> <keyword>test4</...

XSLT Transform XML with Namespaces

I m trying to transform some XML into HTML using XSLT. Problem: I can t get it to work. Can someone tell me what I m doing wrong? XML: <ArrayOfBrokerage xmlns:i="http://www.w3.org/2001/...

XSLT output to HTML

In my XSLT file, I have the following: <input type="button" value= <xsl:value-of select="name">> It s an error as it violates XML rule. What I actually want is having a value from an ...

Mangling IDs and References to IDs in XML

I m trying to compose xml elements into each other, and the problem I am having is when there s the same IDs. Basically what I need to do is mangle all the IDs in an xml file, as well as the ...

Sharepoint 2007 Data view Webpart custom parameters

I m sort of new to the custom parameters that can be setup on a DataView Webpart. There are 6 options: - None - Control - Cookie - Form - QueryString - Server Variable I think that None, Cookie and ...

热门标签