Here's another mindblower, maybe just easy for you.
I have two lists, one is a map that connects item-ids to group-ids, the second one is the item list with simple values. I need to accumulate the number of item-values to group-totals. Originally the two lists are based in different XML-Files.
<!-- List 1 mapping-->
<mapping>
<sub id="1" item="a" group="a">
<sub id="2" item="b" group="a">
<sub id="3" item="d" group="b">
<sub id="4" item="e" group="b">
<sub id="5" item="f" group="c">
</mapping>
<!-- List 2 items -->
<items>
<item id="a" val="OK"/>
<item id="b" val="ERROR"/>
<item id="c" val="OK"/>
<item id="d" val="OK"/>
<item id="e" val="OK"/>
<item id="f" val="OK"/>
</items>
My current approach:
<xsl:variable name="failed-total">
<xsl:variable name="groups-total">
<xsl:value-of select="count(mapping//sub[not(@group=preceding-sibling::sub/@group)])"/>
</xsl:variable>
<!--Selecting the unique groups of the first list:-->
<xsl:for-each select="mapping//sub[not(@group=preceding-sibling::sub/@group)]">
<xsl:variable name="failed">
<xsl:value-of select="items/item[@id=current()/@item and val='ERROR']"/>
</xsl:variable>
<!-- TODO: add value of failed to failed-total value -->
</xsl:for-each>
Needed Output:
Number of Groups: 3
Groups failed: 1
Changing list 2 to the following:
<!-- List 2 items -->
<items>
<item id="a" val="ERROR"/>
<item id="b" val="ERROR"/>
<item id="c" val="OK"/>
<item id="d" val="OK"/>
<item id="e" val="OK"/>
<item id="f" val="OK"/>
</items>
Should then output the same, cause item a and be are in the same group:
Number of Groups: 3
Groups failed: 1
Any hints welcome.
Here is a short and simple solution (just one template), that reads the items.xml document from a local file:
When this transformation is applied on the provided XML document (mappings):
and the second provided XML document (items) is in the file:
C:\temp\delete\items.xml
:the wanted, correct result is produced:
If we modify the items.xml document to:
then again the correct result is produced:
If we modify items.xml to this:
again the correct result is produced:
Assuming all of the XML you provided is in a single input XML document (which isn't entirely clear from your question) this should work:
When run on this input:
The result is:
Here is an approach you can use when the
mapping
anditems
elements are stored in separate variables from different XML documents: