Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/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
Xml XSL |通过查找文档进行排序_Xml_Xslt_Sorting_Document - Fatal编程技术网

Xml XSL |通过查找文档进行排序

Xml XSL |通过查找文档进行排序,xml,xslt,sorting,document,Xml,Xslt,Sorting,Document,吞下第一根柱子 形势 我使用两个XML文件进行XSL转换。文件1处理存储,而文件2存储布局信息 资料 布局 我只提取了布局XML中列出的节点: <xsl:for-each select="item[@id=document($document)//topnews/item]" /> 问题 通过layoutXML中的vieworder属性对数据进行排序时遇到严重问题。我非常感谢任何帮助,并愿意向大师们学习!: +1问好第一个问题。这就是我要做的 data.xml layout.xm

吞下第一根柱子

形势 我使用两个XML文件进行XSL转换。文件1处理存储,而文件2存储布局信息

资料

布局

我只提取了布局XML中列出的节点:

<xsl:for-each select="item[@id=document($document)//topnews/item]" />
问题
通过layoutXML中的vieworder属性对数据进行排序时遇到严重问题。我非常感谢任何帮助,并愿意向大师们学习!:

+1问好第一个问题。这就是我要做的

data.xml

layout.xml

XSLT1.0

output.xml


能否使用Saxon 9或AltovaXML支持的XSLT 2.0

有了它,你就可以简单地做到

<xsl:variable name="layout-doc" select="document('layout.xml')"/>

<xsl:key name="k1" match="topnews/item" use="."/>

<xsl:template match="/">
  <xsl:for-each select="//item[key('k1', @id, $layout-doc)]">
    <xsl:sort select="xs:integer(key('k1', @id, $layout-doc)/@vieworder)"/>
  </xsl:for-each>
</xsl:template>
<xsl:for-each select="item[@id=document($document)//topnews/item]" />
<doc>
  <item id="1100724">
    <node1>Should be second.</node1>
  </item>
  <item id="1100326">
    <node1>Should be first.</node1>
  </item>
</doc>
<topnews>
  <item vieworder="1">1100326</item>
  <item vieworder="2">1100724</item>
</topnews>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="/doc">
    <doc>
      <xsl:apply-templates select="item">
        <xsl:sort select="document('layout.xml')/topnews/item[.=current()/@id]/@vieworder" data-type="number"/>
      </xsl:apply-templates>      
    </doc>
  </xsl:template>

</xsl:stylesheet>
<doc>
   <item id="1100326">
      <node1>Should be first.</node1>
   </item>
   <item id="1100724">
      <node1>Should be second.</node1>
   </item>
</doc>
<xsl:variable name="layout-doc" select="document('layout.xml')"/>

<xsl:key name="k1" match="topnews/item" use="."/>

<xsl:template match="/">
  <xsl:for-each select="//item[key('k1', @id, $layout-doc)]">
    <xsl:sort select="xs:integer(key('k1', @id, $layout-doc)/@vieworder)"/>
  </xsl:for-each>
</xsl:template>