I have studied various solutions on this board but I am afraid I am still a bit stuck - do I need to use Muenchian grouping using keys or will preceding sibling help with item type W.
In brief, there are multiple faRecord nodes - the first item element in each record denotes what type of record it is - C, W here, but there are other types too.
The XSL I have till now will convert these records into Categories and workcodes but I am stumped as to how I can get workcodes to nest inside categories. The sequence could be C W W W C W C C W W W and so on. None of the values are unique. (There will be items nested inside workcodes and so on - but this is the first step. Each category will have 0 or more workcodes. Each workcode may have 0 or more items.)
This is the XML
<?xml version="1.0" encoding="UTF-8"?>
<EstimateDisplayRequest>
<facXML>
<faRecord>
<recordCode>33</recordCode>
<item>
<itemMapCode>1</itemMapCode>
<itemValue>C</itemValue>
</item>
<item>
<itemMapCode>80</itemMapCode>
<itemValue>0</itemValue>
</item>
<item>
<itemMapCode>81</itemMapCode>
<itemValue>INTERNAL CREATIVE</itemValue>
</item>
<item>
<itemMapCode>82</itemMapCode>
<itemValue>TOTAL INTERNAL CREAT</itemValue>
</item>
</faRecord>
<faRecord>
<recordCode>33</recordCode>
<item>
<itemMapCode>1</itemMapCode>
<itemValue>W</itemValue>
</item>
<item>
<itemMapCode>41</itemMapCode>
<itemValue>0</itemValue>
</item>
<item>
<itemMapCode>42</itemMapCode>
<itemValue>TI</itemValue>
</item>
<item>
<itemMapCode>43</itemMapCode>
<itemValue>Time Work Code</itemValue>
</item>
</faRecord>
<faRecord>
<recordCode>33</recordCode>
<item>
<itemMapCode>1</itemMapCode>
<itemValue>W</itemValue>
</item>
<item>
<itemMapCode>41</itemMapCode>
<itemValue>0</itemValue>
</item>
<item>
<itemMapCode>42</itemMapCode>
<itemValue>TI</itemValue>
</item>
<item>
<itemMapCode>43</itemMapCode>
<itemValue>Time Work Code</itemValue>
</item>
</faRecord>
<faRecord>
<recordCode>33</recordCode>
<item>
<itemMapCode>1</itemMapCode>
<itemValue>C</itemValue>
</item>
<item>
<itemMapCode>80</itemMapCode>
<itemValue>1</itemValue>
</item>
<item>
<itemMapCode>81</itemMapCode>
<itemValue>EXTERNAL CREATIVE</itemValue>
</item>
<item>
<itemMapCode>82</itemMapCode>
<itemValue>TOTAL EXTERNAL CREAT</itemValue>
</item>
</faRecord>
<faRecord>
<recordCode>33</recordCode>
<item>
<itemMapCode>1</itemMapCode>
<itemValue>W</itemValue>
</item>
<item>
<itemMapCode>41</itemMapCode>
<itemValue>0</itemValue>
</item>
<item>
<itemMapCode>42</itemMapCode>
<itemValue>TI2</itemValue>
</item>
<item>
<itemMapCode>43</itemMapCode>
<itemValue>Time Work Code</itemValue>
</item>
</faRecord>
</facXML>
</EstimateDisplayRequest>
This is the XSL I have so far:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="EstimateDisplayRequest">
<MCSResponse>
<EstimateDisplayResponse>
<xsl:apply-templates select="*" mode="EstimateDisplayResponse" />
</EstimateDisplayResponse>
</MCSResponse>
</xsl:template>
<xsl:template match="faRecord[item/itemMapCode='1' and item/itemValue='C']" mode="EstimateDisplayResponse">
<EstimateDisplayResponseDetailCategory>
<xsl:attribute name="id"><xsl:number/></xsl:attribute>
<xsl:apply-templates select="child::*[not(self::recordCode)]" />
</EstimateDisplayResponseDetailCategory>
</xsl:template>
<xsl:template match="faRecord[item/itemMapCode='1' and item/itemValue='W']" mode="EstimateDisplayResponse">
<EstimateDisplayResponseDetailWorkcode>
<xsl:attribute name="id"><xsl:number/></xsl:attribute>
<xsl:apply-templates select="child::*[not(self::recordCode)]" />
</EstimateDisplayResponseDetailWorkcode>
</xsl:template>
<xsl:template match="item[itemMapCode='1']" />
<xsl:template match="item[itemMapCode='80']" >
<CategoryCode>
<xsl:value-of select="./itemValue" />
</CategoryCode>
</xsl:template>
<xsl:template match="item[itemMapCode='81']" >
<CategoryName>
<xsl:value-of select="./itemValue" />
</CategoryName>
</xsl:template>
<xsl:template match="item[itemMapCode='82']" >
<CategoryTotalName>
<xsl:value-of select="./itemValue" />
</CategoryTotalName>
</xsl:template>
<xsl:template match="item[itemMapCode='41']" >
<WorkCodeCategory>
<xsl:value-of select="./itemValue" />
</WorkCodeCategory>
</xsl:template>
<xsl:template match="item[itemMapCode='42']" >
<WorkCode>
<xsl:value-of select="./itemValue" />
</WorkCode>
</xsl:template>
<xsl:template match="item[itemMapCode='43']" >
<WorkCodeName>
<xsl:value-of select="./itemValue" />
</WorkCodeName>
</xsl:template>
</xsl:stylesheet>
TIA!
[Sorry, I should've listed the output as well - a list of categories. I tried using a for-each for categories with following-siblings but I end up getting ALL remaining workcode elements as I go down the nodes - which is expected I guess :( ]
<mcsresponse>
<estimatedisplayresponse>
<estimatedisplayresponsedetailcategory id="1">
<categorycode>0</categorycode>
<categoryname>INTERNAL CREATIVE</categoryname>
<categorytotalname>TOTAL INTERNAL CREAT</categorytotalname>
<estimatedisplayresponsedetailworkcode id="2">
<workcodecategory>0</workcodecategory>
<workcode>TI</workcode>
<workcodename>Time Work Code</workcodename>
</estimatedisplayresponsedetailworkcode>
<estimatedisplayresponsedetailworkcode id="3">
<workcodecategory>0</workcodecategory>
<workcode>TI</workcode>
<workcodename>Time Work Code</workcodename>
</estimatedisplayresponsedetailworkcode>
</estimatedisplayresponsedetailcategory>
<estimatedisplayresponsedetailcategory id="4">
<categorycode>0</categorycode>
<categoryname>INTERNAL CREATIVE</categoryname>
<categorytotalname>TOTAL INTERNAL CREAT</categorytotalname>
<else>YNNYN</else>
<estimatedisplayresponsedetailworkcode id="5">
<workcodecategory>0</workcodecategory>
<workcode>TI</workcode>
<workcodename>Time Work Code</workcodename>
</estimatedisplayresponsedetailworkcode>
</estimatedisplayresponsedetailcategory>
</estimatedisplayresponse>
</mcsresponse>