how group values of elements <seg> in xml source, using explicit cross-references created @corresp attributes?
<div> <div id="fr"> <seg id="fr_1" corresp="#en_1">abc</seg> <seg id="fr_2" corresp="#en_2 #en3">def</seg> <seg id="fr_3" corresp="#en_3 #en_4">ghi</seg> <seg id="fr_4" corresp="#en_4 #en_5">jkl</seg> <seg id="fr_5" corresp="#en_6">mno</seg> </div> <div id="en"> <seg id="en_1" corresp="#fr_1">ab</seg> <seg id="en_2" corresp="#fr_1 #fr_2">cde</seg> <seg id="en_3" corresp="#fr_2 #fr_3">fg</seg> <seg id="en_4" corresp="#fr_3 #fr_4">hij</seg> <seg id="en_5" corresp="#fr_4">kl</seg> <seg id="en_6" corresp="#fr_5">mno</seg> </div> </div>
the xslt-transformed output should follows:
<div> <ul> <li>abc<br/>ab</li> <li>abc<br/>cde</li> <li>def<br/>cde</li> <li>def<br/>fg</li> <li>ghi<br/>fg</li> <li>ghi<br/>hij</li> <li>jkl<br/>hij</li> <li>jkl<br/>kl</li> <li>mno<br/>mno</li> </ul> </div>
thanks!
@jirka, here similar input further elements nested within element. , corresp attribute defines cross-references among these new elements . modified input looks follows:
<div> <div id="fr"> <seg id="fr_1"><w id="fr1" corresp="#en2">aa</w> <w id="fr2" corresp="#en3">bb</w>, <w id="fr3" corresp="#en1">cc</w>.</seg> <seg id="fr_2"><w id="fr1" corresp="#en1">dd</w> <w id="fr2" corresp="#en3">ee</w>?</seg> <seg id="fr_3"><w id="fr1" corresp="#en1">ff</w> <w id="fr2" corresp="#en3">gg</w><w id="fr3" corresp="#en2">hh</w></seg> </div> <div id="en"> <seg id="en_1"><w id="en1" corresp="#fr3">ax</w><w id="en2" corresp="#fr1">bx</w><w id="en3" corresp="#fr2">cx</w></seg> <seg id="en_2"><w id="en1" corresp="#fr1">dx</w><w id="en2" corresp="#en0">ex</w><w id="en3" corresp="#en2">fx</w></seg> <seg id="en_3"><w id="en1" corresp="#fr1">hx</w> <w id="en2" corresp="#en3">ix</w><w id="en3" corresp="#en2">jx</w>.</seg> </div>
and output needed should follows:
<div> <ol> <li><w>aa</w> : <w>bx</w><br/><w>bb</w> : <w>ax</w><br/> </li> <li><w>dd</w> : <w>dx</w><w>ee</w> : <w>fx</w><br/><br/> </li> <li><w>ff</w> :<w>hx</w><br/> <w>gg</w> :<w>jx</w><br/><w>hh</w>:<w>ix</w><br/></li> </ol> </div>
you may try slight adaption of answer last question:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" indent="yes"/> <xsl:key name="ksegid" match="seg" use="@id"/> <xsl:template match="/div"> <html> <head> <title></title> </head> <body> <ul> <xsl:apply-templates select="div[@id='en']/seg"/> </ul> </body> </html> </xsl:template> <xsl:template match="seg"> <xsl:call-template name="findtarget"> <xsl:with-param name="targets" select="@corresp" /> </xsl:call-template> </xsl:template> <xsl:template name="findtarget"> <xsl:param name="targets" /> <xsl:choose> <xsl:when test="contains($targets, ' ')"> <xsl:call-template name="findtarget"> <xsl:with-param name="targets" select="substring-before($targets,' ')" /> </xsl:call-template> <xsl:call-template name="findtarget"> <xsl:with-param name="targets" select="substring-after($targets,' ')" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <li> <xsl:value-of select="key('ksegid',substring-after($targets, '#'))"/> <br/> <xsl:value-of select="."/> </li> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
which generate following output:
<?xml version="1.0"?> <html> <head> <title/> </head> <body> <ul> <li>abc<br/>ab</li> <li>abc<br/>cde</li> <li>def<br/>cde</li> <li>def<br/>fg</li> <li>ghi<br/>fg</li> <li>ghi<br/>hij</li> <li>jkl<br/>hij</li> <li>jkl<br/>kl</li> <li>mno<br/>mno</li> </ul> </body> </html>
Comments
Post a Comment