Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xslt 相邻元素相同的xsl编号_Xslt_Xpath - Fatal编程技术网

Xslt 相邻元素相同的xsl编号

Xslt 相邻元素相同的xsl编号,xslt,xpath,Xslt,Xpath,我需要用以下结构格式化一些xml数据 <list> <item> Test </item> <item> Testt </item> <or-item> TestOr </or-item> <or-item> TestOrr </or-item> <item> Testtt </item>

我需要用以下结构格式化一些xml数据

<list>
  <item>
    Test
  </item>
  <item>
    Testt
  </item>
  <or-item>
    TestOr
  </or-item>
  <or-item>
    TestOrr
  </or-item>
  <item>
    Testtt
  </item>
  <or-item>
    TestOrrr
  </or-item>
  <item>
    Testttt
  </item>
</list>

编辑

我在linux上使用XSLT1.1和xsltproc,但如果必要,可以使用2.0


由于目标格式是HTML,您似乎可以依靠使用
xsl:for each group
group start with=“item”
来创建适当的嵌套HTML有序列表:


由于目标格式是HTML,您似乎可以依靠使用
xsl:for each group
group start with=“item”
来创建适当的嵌套HTML有序列表:


只需调整
xsl:number指令即可生成预期的输出:

XSLT1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8"/>

<xsl:template match="/list">
    <div>
        <xsl:apply-templates/>
    </div>
</xsl:template>

<xsl:template match="item">
    <div>
        <xsl:number/>
        <xsl:value-of select="."/>
    </div>
</xsl:template>

<xsl:template match="or-item">
    <div style="padding-left: 10px">
        <xsl:number level="any" from="item" format="a) "/>
        <xsl:value-of select="."/>
    </div>
</xsl:template>

</xsl:stylesheet>

只需调整
xsl:number指令
:

XSLT1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8"/>

<xsl:template match="/list">
    <div>
        <xsl:apply-templates/>
    </div>
</xsl:template>

<xsl:template match="item">
    <div>
        <xsl:number/>
        <xsl:value-of select="."/>
    </div>
</xsl:template>

<xsl:template match="or-item">
    <div style="padding-left: 10px">
        <xsl:number level="any" from="item" format="a) "/>
        <xsl:value-of select="."/>
    </div>
</xsl:template>

</xsl:stylesheet>


能否向我们展示您希望为所展示的XML示例生成的结果?您使用哪个XSLT处理器,哪个XSLT版本I1.1从未真正作为规范存在过?您能告诉我们您想要为您展示的XML示例生成的结果吗?您使用哪个XSLT处理器,哪个XSLT版本I1.1从未真正作为规范存在过?嗯
saxon
知道
tail
函数,但是
Altova
中存在问题。。。有什么替代品吗?@Pascal,是的,
tail(current-group())
本质上是
current-group()[position()gt 1]
子序列(current-group(),2)
。嗯
saxon
知道
tail
函数,但
Altova
中存在问题。。。有什么替代品吗?@Pascal,是的,
tail(current-group())
本质上是
current-group()[position()gt 1]
子序列(current-group(),2)
  <xsl:template match="list">
      <xsl:variable name="nested-list">
          <xsl:for-each-group select="*" group-starting-with="item">
              <xsl:copy>
                  <xsl:value-of select="."/>
                  <xsl:copy-of select="tail(current-group())"/>
              </xsl:copy>
          </xsl:for-each-group>              
      </xsl:variable>
      <div>
        <xsl:apply-templates select="$nested-list"/>
      </div>
  </xsl:template>

  <xsl:template match="item">
    <div>
      <xsl:number/>
      <xsl:apply-templates/>
    </div>
  </xsl:template>

  <xsl:template match="or-item">
    <div style="padding-left: 10px">
      <xsl:number format="a) "/>
      <xsl:value-of select="."/>
    </div>
  </xsl:template>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8"/>

<xsl:template match="/list">
    <div>
        <xsl:apply-templates/>
    </div>
</xsl:template>

<xsl:template match="item">
    <div>
        <xsl:number/>
        <xsl:value-of select="."/>
    </div>
</xsl:template>

<xsl:template match="or-item">
    <div style="padding-left: 10px">
        <xsl:number level="any" from="item" format="a) "/>
        <xsl:value-of select="."/>
    </div>
</xsl:template>

</xsl:stylesheet>