Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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

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以预定义的顺序回显XML元素?_Xml_Xslt - Fatal编程技术网

如何使用XSLT以预定义的顺序回显XML元素?

如何使用XSLT以预定义的顺序回显XML元素?,xml,xslt,Xml,Xslt,如何以预定义的顺序输出XML元素?一种可能的阵列式解决方案如果有这样的解决方案,那就太好了 我有很多元素名称不同的XML,它们将在同一时间进行转换,但正如您所看到的,它们都将以相同的方式进行响应。我的问题是,他们的顺序不正确,我希望他们在相同的顺序一样 id, name, description, price, image, url, category, category_id, shopid 这是我的XSLT <xsl:stylesheet version="1.0" xmlns:xs

如何以预定义的顺序输出XML元素?一种可能的阵列式解决方案如果有这样的解决方案,那就太好了

我有很多元素名称不同的XML,它们将在同一时间进行转换,但正如您所看到的,它们都将以相同的方式进行响应。我的问题是,他们的顺序不正确,我希望他们在相同的顺序一样

id, name, description, price, image, url, category, category_id, shopid
这是我的XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:include href="identity.xsl"/>

    <xsl:template match="/*">
        <products>
            <xsl:for-each select="file">
                <xsl:apply-templates 
                    select="document(.)/*//product">
                    <xsl:with-param name="file" select="."/>
                </xsl:apply-templates>
            </xsl:for-each>
        </products>
    </xsl:template>

    <xsl:template match="product">
        <xsl:param name="file"/>
        <xsl:copy>

            <xsl:apply-templates select="@*"/>

            <xsl:if test="not(id)">
                <id><xsl:value-of select="@id"/></id>
            </xsl:if>

            <xsl:apply-templates select="node()"/>

            <catid><xsl:value-of select="category/@id"/></catid>
            <shopid><xsl:value-of select="$file"/></shopid>

        </xsl:copy>
    </xsl:template>


<xsl:template match="title">
  <name>
        <xsl:apply-templates select="node() | @*" />
  </name>
</xsl:template>
<xsl:template match="price_with_vat">
  <price>
        <xsl:apply-templates select="node() | @*" />
  </price>
</xsl:template>
<xsl:template match="link">
  <url>
        <xsl:apply-templates select="node() | @*" />
  </url>
</xsl:template>

    <xsl:template match="category/@id
        | product/@id | availability | manufacturer | shipping | sku | ssku | thumbnail | stock | weight | mpn | instock"/>

</xsl:stylesheet>

因为您使用的是标识转换,所以可以通过单独应用模板来定义输出元素的顺序。例如:

<xsl:template match="product">
    <xsl:param name="file"/>
    <xsl:copy>

        <xsl:apply-templates select="@*"/>

        <xsl:if test="not(id)">
            <id><xsl:value-of select="@id"/></id>
        </xsl:if>

        <xsl:apply-templates select="name"/>
        <xsl:apply-templates select="description"/>
        <xsl:apply-templates select="price"/>
        <xsl:apply-templates select="image"/>
        <xsl:apply-templates select="url"/>
        <xsl:apply-templates select="category"/>

        <catid><xsl:value-of select="category/@id"/></catid>
        <shopid><xsl:value-of select="$file"/></shopid>

    </xsl:copy>
</xsl:template>

因为您使用的是标识转换,所以可以通过单独应用模板来定义输出元素的顺序。例如:

<xsl:template match="product">
    <xsl:param name="file"/>
    <xsl:copy>

        <xsl:apply-templates select="@*"/>

        <xsl:if test="not(id)">
            <id><xsl:value-of select="@id"/></id>
        </xsl:if>

        <xsl:apply-templates select="name"/>
        <xsl:apply-templates select="description"/>
        <xsl:apply-templates select="price"/>
        <xsl:apply-templates select="image"/>
        <xsl:apply-templates select="url"/>
        <xsl:apply-templates select="category"/>

        <catid><xsl:value-of select="category/@id"/></catid>
        <shopid><xsl:value-of select="$file"/></shopid>

    </xsl:copy>
</xsl:template>


谢谢!(你忘了关上标签)真遗憾,这是在睡梦中发生的事情。我在度假,有史以来最糟糕的关系。我很高兴有人能编辑这篇感谢你的文章。再次感谢!谢谢(你忘了关上标签)真遗憾,这是在睡梦中发生的事情。我在度假,有史以来最糟糕的关系。我很高兴有人能编辑这篇感谢你的文章。再次感谢!