I am trying to transform this document but am fairly new to xslt and having tons of fun trying to get it right. The core node(truncated for simplicity) looks like this
<Product prod_id="6352">
<brandId>221</brandId>
<brand>Oscar Mayer</brand>
<images>
<smallimage>text</simage>
<medimage>text</medimage>
<largeimage>text</limage>
</images>
<nutrition>
<nutritionShow>Y</nutritionShow>
<servingSize>1 SLICE</servingSize>
<servingsPerContainer>12</servingsPerContainer>
<totalCalories>60</totalCalories>
<fatCalories>35</fatCalories>
<totalFat>4</totalFat>
<totalFatPercent>6</totalFatPercent>
<totalFatUnit>g</totalFatUnit>
<saturatedFat>1.5</saturatedFat>
<saturatedFatPercent>8</saturatedFatPercent>
<saturatedFatUnit>g</saturatedFatUnit>
<transFat>0</transFat>
<transFatUnit>g</transFatUnit>
<cholesterolUnit>mg</cholesterolUnit>
</nutrition>
<prodId>6352</prodId>
</Product>
In the end I want to sub-nodes that are grouped logically to be a single node with appropriate attribute names.
The end result should look like this
<Product prod_id="6352">
<brandId>221</brandId>
<brand>Oscar Mayer</brand>
<images>
<smallimage>text</smallimage>
<medimage>text</medimage>
<largeimage>text</largeimage>
</images>
<nutrition>
<nutritionShow>Y</nutritionShow>
<servingSize>1 SLICE</servingSize>
<servingsPerContainer>12</servingsPerContainer>
<totalCalories>60</totalCalories>
<fatCalories>35</fatCalories>
<totalFat amount="4" percent="6" unit="g" />
<saturatedFat amount="1.5" percent="8" unit="g"/>
<transFat amount="0" unit="g"</>
</nutrition>
<prodId>6352</prodId>
Some key features are
- group the similar attributes(notice saturatedFat and transFat ... slightly different)I have a discrete list of these sets. You could use a list or something more dynamic based on relationships but notice the variance.
- leave other(non group-able) attributes be
- ignore groups that lack the amount attribute/only have unit attribute(notice cholesterol)
Thanks in advance for helping me to understand this fairly complex transformation.