xml - Combining multiple elements based on their children element values with XSLT -
alright xslt apparently beyond me , need please. haven't been able put multiple stack overflow posts exist 1 coherent, working section of code. have xml file has multiple entries this
<?xml version="1.0" encoding="utf-8"?> <events> <event> <eventtype>blah</eventtype> <title>blah blah</title> <relatedlocations>blah</relatedlocations> <date>friday, september 2, 2016</date> <dateyear>2016</dateyear> <datemonth>09</datemonth> <dateday>02</dateday> <body>derp</body> <notes>notes not displayed public.</notes> </event> <event> <eventtype>blah</eventtype> <title>blah blah</title> <relatedlocations>blah</relatedlocations> <date>friday, october 7, 2016</date> <dateyear>2016</dateyear> <datemonth>09</datemonth> <dateday>07</dateday> <body>derp</body> <notes>notes not displayed public.</notes> </event> </events> and combine them based on titles being same , relatedlocations being same read this
<event> <eventtype>blah</eventtype> <title>blah blah</title> <relatedlocations>blah</relatedlocations> <date>friday, september 2, 2016, friday, october 7, 2016</date> <dateyear>2016</dateyear> <datemonth>09</datemonth> <dateday>07</dateday> <body>derp</body> <notes>notes not displayed public.</notes> </event> the problem there other nodes in sheet totally different , same have different location. i'd if statement (i think?) checks whole document , same current node , concatenate dates 1 node , leave other nodes alone. code i've come with
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output encoding="utf-8" indent="yes" method="xml" /> <xsl:strip-space elements="*"/> <xsl:key name="title" match="event/*" use="concat(../@id, '-', localname())"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:for-each select="event/title"> <xsl:when test = "(@title = preceding::*/@title)"> worked! </xsl:when> </xsl:for-each> <xsl:template match="event"> <xsl:copy> <xsl:apply-templates select="@*" /> <xsl:apply-templates select="title" /> <xsl:apply-templates select="relatedlocations" /> <xsl:apply-templates select="date" /> <xsl:apply-templates select="dateyear" /> <xsl:apply-templates select="datemonth" /> <xsl:apply-templates select="dateday" /> <xsl:apply-templates select="body" /> <xsl:apply-templates select="ageranges" /> </xsl:copy> </xsl:template> which doesn't work. please , thank you.
Comments
Post a Comment