xml - xsl group tags into parents groups -
xml - xsl group tags into parents groups -
i have xml :
<row> <one>1</one> <two>2</two> <three>3</tree> <four>4</four> <five>5</five> <six>6</six> <seven>7</seven> <... <... <... <... <... </row>
and want grouping 1 2 tag main tag , rest (could more hundred of these ) other tag :
expected result :
<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>
my 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>
but on other tag 1 , 2 , want 1 , 2 in main tag.
you're applying templates twice on 1 , two. first explicitely, sec implicitely in sec match : node()|@*. filter them out sec match. xpath should job (not tested, in morning here me) :
<xsl:template match="row"> <main> <xsl:apply-templates select="one|two"/> </main> <others> <!-- no need apply on attributes (@*), unless explicitely want add together rows attributes others element.--> <xsl:apply-templates select="node()[not(name()='one' or name()='two')]"/> </others> </xsl:template>
xml xslt
Comments
Post a Comment