Xml 将标签分组到父组中
我有以下xml:Xml 将标签分组到父组中,xml,xslt,Xml,Xslt,我有以下xml: <Row> <one>1</one> <two>2</two> <three>3</tree> <four>4</four> <five>5</five> <six>6</six> <seven>7&l
<Row>
<one>1</one>
<two>2</two>
<three>3</tree>
<four>4</four>
<five>5</five>
<six>6</six>
<seven>7</seven>
<...
<...
<...
<...
<...
</Row>
我想把一个两个标签归为主标签,其余的都可以归为其他标签:
预期结果:
<Row>
<main>
<one>1</one>
<two>2</two>
<main>
<others>
<three>3</tree>
<four>4</four>
<five>1</five>
<six>2</six>
<seven>3</seven>
<...
<...
<...
<...
<...
<others>
</Row>
我的xslt是:
<?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" omit-xml-declaration="yes" encoding="UTF-8" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Row">
<main>
<xsl:apply-templates select="one|two"/>
</main>
<others>
<xsl:apply-templates select="node()|@*"/>
</others>
</xsl:template>
但是我在另一个标签上也看到了1和2,我希望1和2只出现在主标签中。你在1和2上应用了两次模板。在第二个匹配中,第一个显式地,第二个隐式地:node |@*。 从第二场比赛中筛选出来。 这个xpath应该可以完成未经测试的工作,对我来说还为时过早:
<xsl:template match="Row">
<main>
<xsl:apply-templates select="one|two"/>
</main>
<others>
<!-- No need to apply on attributes (@*),
unless you explicitely want to add rows attributes to others element.-->
<xsl:apply-templates select="node()[not(name()='one' or name()='two')]"/>
</others>
</xsl:template>
请不要多次发布同一问题。