I have two functions that are outputting XML data. Ideally I'd like to combine the outputs of each function into one variable to parse data.
In SQL terms, each function can be joined together by an inner join via the attribute PageId... but joins are not permitted in XSLT (or at least to my knowledge).
Any suggestions on the cleanest/easiest way to combine these functions? The functions I'm calling are built into the cms and cannot be edited.
Some more information:
The first function is the sitemap. It lists the webpage ids and their levels for the website.
The second function pulls webpage ids and their metadata tags that I need combined with the site map.
I thought about creating variables for the second function Page Ids, but the number of pages with the metadata tags changes and I don't believe the variables support dynamic names.
I apologize if I'm not being clear enough as xslt is new to me. Please let me know if more information is needed.
edit: adding code example
<in:inputs xmlns:in="http://www.composite.net/ns/transformation/input/1.0">
<in:result name="SitemapXml">
<Page Id="a0a47ce1-6eba-4d29-a7a3-3749c768c7e7" isopen="true" xmlns="">
<Page Id="a3055286-0e90-4b04-99dd-fb1a61dde0bf" isopen='true' xmlns="">
<Page Id="da675b13-d4d3-42ab-acc1-82e2a5408100" isopen='true' iscurrent='true' Depth="2"/>
</Page>
</Page>
</in:result>
<in:result name="GetisrootXml">
<isroot PageId="a0a47ce1-6eba-4d29-a7a3-3749c768c7e7" Id="f8d4eea4-7070-4bc3-a804-e106697ffaa9" isroot="true" xmlns=""/>
<isroot PageId="f8e4adbc-2758-42d6-bc40-0192ba0107a6" Id="db62e132-3f3b-493f-917a-9e090f887f13" isroot="false" xmlns=""/>
</in:result>
</in:inputs>
What I would like returned:
<in:inputs xmlns:in="http://www.composite.net/ns/transformation/input/1.0">
<in:result name="SitemapXml">
<Page Id="a0a47ce1-6eba-4d29-a7a3-3749c768c7e7" isopen="true" xmlns="" isroot='true'>
</Page>
<Page Id="a3055286-0e90-4b04-99dd-fb1a61dde0bf" isopen='true' xmlns="">
<Page Id="da675b13-d4d3-42ab-acc1-82e2a5408100" isopen='true' iscurrent='true' Depth="2"/>
</in:result>
</in:inputs>
From this, I want to further change the output to fit my needs (add tags for display purposes). In order to get to that point, the isroot attribute needs to be attached to the sitemap.
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:in="http://www.composite.net/ns/transformation/input/1.0">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="kIsRootByPageId" match="isroot" use="@PageId"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="in:result[1]/Page">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:copy-of select="key('kIsRootByPageId',@Id )/@isroot"/>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="in:result[2]"/>
</xsl:stylesheet>
when applied on the provided XML document:
<in:inputs xmlns:in="http://www.composite.net/ns/transformation/input/1.0">
<in:result name="SitemapXml">
<Page Id="a0a47ce1-6eba-4d29-a7a3-3749c768c7e7" isopen="true" xmlns=""></Page>
<Page Id="a3055286-0e90-4b04-99dd-fb1a61dde0bf" isopen='true' xmlns="">
<Page Id="da675b13-d4d3-42ab-acc1-82e2a5408100" isopen='true' iscurrent='true' Depth="2"/></Page>
</in:result>
<in:result name="GetisrootXml">
<isroot PageId="a0a47ce1-6eba-4d29-a7a3-3749c768c7e7" Id="f8d4eea4-7070-4bc3-a804-e106697ffaa9" isroot="true" xmlns=""/>
<isroot PageId="f8e4adbc-2758-42d6-bc40-0192ba0107a6" Id="db62e132-3f3b-493f-917a-9e090f887f13" isroot="false" xmlns=""/>
</in:result>
</in:inputs>
produces the wanted, correct result:
<in:inputs xmlns:in="http://www.composite.net/ns/transformation/input/1.0">
<in:result name="SitemapXml">
<Page Id="a0a47ce1-6eba-4d29-a7a3-3749c768c7e7" isopen="true" isroot="true"/>
<Page Id="a3055286-0e90-4b04-99dd-fb1a61dde0bf" isopen="true">
<Page Id="da675b13-d4d3-42ab-acc1-82e2a5408100" isopen="true" iscurrent="true"
Depth="2"/>
</Page>
</in:result>
</in:inputs>
Explanation:
The identity rule copies "as-is" every node for which this template is selected for execution.
There are two overriding templates, the second of which "deletes" with its empty body the second occurence of in:result.
The first overriding template matches any Page that is a child of the first occurence of in:result. We use keys to efficiently and conveniently find the isroot element that references the current Page in its PageId attribute -- and we copy its isroot attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With