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 - Fatal编程技术网

Xslt 如何使用xsl将元素按属性值移动到最后一个同级位置?

Xslt 如何使用xsl将元素按属性值移动到最后一个同级位置?,xslt,Xslt,我需要将属性id中具有给定值的元素移动(而不是复制)到其同级元素的最后一个位置,例如//ul/li[@id='b']: 输入: a b c d ... 输出: a c d ... b 如果您的输入XML与问题中的一样简单,您可以使用: <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/

我需要将属性id中具有给定值的元素移动(而不是复制)到其同级元素的最后一个位置,例如
//ul/li[@id='b']

输入:

  • a
  • b
  • c
  • d
  • ...
输出:

  • a
  • c
  • d
  • ...
  • b

如果您的输入XML与问题中的一样简单,您可以使用:

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

<xsl:template match="ul">
    <ul>
        <xsl:apply-templates select="li[@id != 'b']"/>
        <xsl:apply-templates select="li[@id = 'b']"/>
    </ul>
</xsl:template>

<xsl:template match="li">
    <xsl:copy-of select="."/>
</xsl:template>
</xsl:transform>


如果您的输入XML与问题中的一样简单,您可以使用:

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

<xsl:template match="ul">
    <ul>
        <xsl:apply-templates select="li[@id != 'b']"/>
        <xsl:apply-templates select="li[@id = 'b']"/>
    </ul>
</xsl:template>

<xsl:template match="li">
    <xsl:copy-of select="."/>
</xsl:template>
</xsl:transform>

这可能有助于:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" indent="yes" encoding="UTF-8" standalone="yes"/>
    <xsl:param name="id" select="string('b')"/>
    <xsl:template match="ul">
        <xsl:element name="ul">
           <xsl:apply-templates select="li[@id!=$id]"/>
           <xsl:apply-templates select="li[@id=$id]"/>
        </xsl:element>
    </xsl:template>

    <xsl:template match="li">
        <xsl:copy-of select="."/>
    </xsl:template>

</xsl:stylesheet>

这可能有助于:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" indent="yes" encoding="UTF-8" standalone="yes"/>
    <xsl:param name="id" select="string('b')"/>
    <xsl:template match="ul">
        <xsl:element name="ul">
           <xsl:apply-templates select="li[@id!=$id]"/>
           <xsl:apply-templates select="li[@id=$id]"/>
        </xsl:element>
    </xsl:template>

    <xsl:template match="li">
        <xsl:copy-of select="."/>
    </xsl:template>

</xsl:stylesheet>


“具有给定值的元素”如何给定?@michael.hor257k我的意思是以值“b”为例是的,但该值如何“给定”?您是在运行时将其作为参数传递给样式表,还是什么?@michael.hor257k我的意思是“给定”为“指定或声明”。同义词:“特定”、“特定”1。请不要无礼。2.值“b”未出现在您的输入中。处理器只能使用给定的输入。因此,b'值从何而来的问题是这里自然要问的问题。“具有给定值的元素”如何给定?@michael.hor257k我的意思是以值“b”为例是的,但该值如何“给定”?您是在运行时将其作为参数传递给样式表,还是什么?@michael.hor257k我的意思是“给定”为“指定或声明”。同义词:“特定”、“特定”1。请不要无礼。2.值“b”未出现在您的输入中。处理器只能使用给定的输入。因此,b'值从何而来的问题是这里自然要问的问题。谢谢。这就是我想要的。你的答案排在第一位,所以没有核对。谢谢。这就是我想要的。你的答案排在第一位,所以没有核对。谢谢。那正是我想要的。谢谢。这就是我想要的。