Html 如何使用xslt设计xml样式,同时保持标记的原始顺序?

Html 如何使用xslt设计xml样式,同时保持标记的原始顺序?,html,xml,xslt,Html,Xml,Xslt,问题出在这里。我有一个xml文件,其中有多个标记,根据编写它们的人的不同,它们可能以任何顺序结束。我需要创建一个xls文件来设置样式,同时保持标签的原始顺序。以下是xml: <content> <h>this is a header</h> <p>this is a paragraph</p> <link>www.google.com</link> <h> another header!</h&

问题出在这里。我有一个xml文件,其中有多个标记,根据编写它们的人的不同,它们可能以任何顺序结束。我需要创建一个xls文件来设置样式,同时保持标签的原始顺序。以下是xml:

<content>
<h>this is a header</h>
<p>this is a paragraph</p>
<link>www.google.com</link>
<h> another header!</h>
</content>

XSLT不会自行对元素重新排序,除非您告诉它这样做。如果您正在匹配元素,并用其他元素替换它们,它将按照我找到它们的顺序处理它们

如果您希望简单地用HTML元素替换元素,那么只需为每个元素编写一个匹配的模板,在那里输出所需的HTML元素。例如,要用h1元素替换h元素,可以这样做

<xsl:template match="h">
   <h1>
      <xsl:apply-templates select="@*|node()"/>
   </h1>
</xsl:template>
h1元素将在原始文档中h元素所在的位置输出。这是完整的XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output method="html" indent="yes"/>

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

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

   <xsl:template match="link">
      <a href="{text()}">
         <xsl:apply-templates select="@*|node()"/>
      </a>
   </xsl:template>

   <xsl:template match="@*|node()">
      <xsl:copy>
         <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
   </xsl:template>
</xsl:stylesheet>
应用于示例文档时,将输出以下内容

<body>
   <h1>this is a header</h1>
   <p>this is a paragraph</p>
   <a href="www.google.com">www.google.com</a>
   <h1> another header!</h1>
</body>

您当前的XSLT是什么?您在哪里遇到了问题?我发现有点难以想象您是如何编写代码来对这些元素重新排序的,而不必付出很大的努力。如果你给我们看你的代码,我们就能告诉你哪里出了问题。我不想重新排列元素。。。正如我在文章中所说的,如果您不展示XSLT,您是否至少会向我们展示所需的输出?