xml - XSLT: Combine elements without duplicated -



xml - XSLT: Combine elements without duplicated -

i want transformation xml text combining elements, avoiding duplicates in output. xml that:

<a> <b> <param1>value0</param1> <param2>value1</param2> </b> <b> <param1>value2</param1> <param2>value3</param2> </b> <c> <param3>valuec1</param3> <d> <param4>value0</param4> <param5>value4</param5> </d> <d> <param4>value0</param4> <param5>value5</param5> </d> <d> <param4>value2</param4> <param5>value6</param5> </d> </c> <c> <param3>valuec2</param3> <d> <param4>value0</param4> <param5>value5</param5> </d> </c> </a>

and output:

object: param1=value0, param2=value1, param3=valuec1, param4=value0; object: param1=value2, param2=value3, param3=valuec1, param4=value2; object: param1=value0, param2=value1, param3=valuec2, param4=value0;

notes:

for every d object, match b objects using d.param4 = b.param1 if there 2 or more d objects same c , matching same b, print 1 of them (in example, nil done sec d object because produce same line first one) if there 2 d objects matching same b, different c's, print both (third row in output example)

i looked similar question, couldn't find in same case.

i guess done using keys, it's complex.

thanks!

regards, ale.

ps: sorry english.

given you're not making utilize of param5 in output appear possible simplify problem to

for each c find distinct b elements param1 matches param4 of any of contained ds for each of extract b/param1, b/param2, currentc/param3, b/param1 1 time again (but labelled param4)

this 1 way accomplish using templates.

class="lang-xml prettyprint-override"><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:output method="text" /> <xsl:key name="bbyparam1" match="b" use="param1" /> <xsl:template match="/"> <xsl:apply-templates select="a/c" /> </xsl:template> <xsl:template match="c"> <xsl:apply-templates select="key('bbyparam1', d/param4)"> <xsl:with-param name="currentc" select="." /> </xsl:apply-templates> </xsl:template> <xsl:template match="b"> <xsl:param name="currentc" /> <xsl:text>object: param1=</xsl:text> <xsl:value-of select="param1" /> <xsl:text>, param2=</xsl:text> <xsl:value-of select="param2" /> <xsl:text>, param3=</xsl:text> <xsl:value-of select="$currentc/param3" /> <xsl:text>, param4=</xsl:text> <xsl:value-of select="param1" /> <xsl:text>&#10;</xsl:text> </xsl:template> </xsl:stylesheet>

"find distinct b elements param1 matches param4 of any of contained ds" straightforward due fact when pass node set sec argument key function exactly - returns set of nodes key value string value of any of nodes in argument node set, , returned node set (being set) guaranteed contain no duplicates.

xml xslt

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -