特定序列的变换 [英] transformation in particular sequence
本文介绍了特定序列的变换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可以在元素树中向上或向下移动 xml 元素.
I would like to know that is it possible to move xml element up or down in element tree.
输入的 xml.
<ROOT>
<A1>A</A1>
<B1>B</B1>
<C1>C</C1>
<D1>D</D1>
</ROOT>
所需的输出 xml.
<ROOT>
<A1>A</A1>
<D1>D</D1>
<B1>B</B1>
<C1>C</C1>
</ROOT>
XSD 序列规则
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="ROOT">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="A1"/>
<xs:element type="xs:string" name="D1"/>
<xs:element type="xs:string" name="B1"/>
<xs:element type="xs:string" name="C1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
谁能给我提供一些 XSLT 示例来做这样的事情?提前感谢您的任何帮助.
Can anyone provide me some XSLT example to do this such of thing? Thank you for any help in advance.
推荐答案
Martin Honnen 帮助我从其他帖子中获得答案,因此只是想分享答案以帮助他人,但我仍然想知道是否还有其他方法可以做这 - 就像在这种方法中一样,如果 XSD 标记序列发生变化,则必须也更改 xsl 序列.
Martin Honnen help me to get answer from other post, hence just thought to share answer to help others but still I am wondering if there is any other way to do this - as in this approach if there is change in XSD tag sequence one has to change xsl sequence too.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ROOT">
<ROOT>
<xsl:apply-templates select="A1"/>
<xsl:apply-templates select="D1"/>
<xsl:apply-templates select="C1"/>
<xsl:apply-templates select="B1"/>
</ROOT>
</xsl:template>
<xsl:template match="A1">
<a1>
<xsl:apply-templates />
</a1>
</xsl:template>
<xsl:template match="B1">
<b1>
<xsl:apply-templates />
</b1>
</xsl:template>
<xsl:template match="C1">
<c1>
<xsl:apply-templates />
</c1>
</xsl:template>
<xsl:template match="D1">
<d1>
<xsl:apply-templates />
</d1>
</xsl:template>
</xsl:stylesheet>
这篇关于特定序列的变换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文