I need to write an extensive XSLT that doesn't output (removes) any element that is empty. For Attributes, this means that if the value of the path is empty, it will not populate that attribute in the output. For Nodes, this means that if there isn't any data (empty attributes or child nodes without attributes/data) it will not populate that node in the output. Below is an example related to Baseball to better explain what I'm looking for.
How the output looks like now:
<Baseball>
<Fields>
<Equipment>
<Bats>
<Bat Brand="Louisville" Model="16534" Length="34" Weight="30" Description="Composite" />
<Bat Brand="Easton" Model="asdfer" Length="32" Weight="29" Description="" />
<Bat Brand="" Model="" Length="" Weight="" Description="" />
</Bats>
<Gloves>
<Glove Brand="" Model="" Length="" Description="" />
</Gloves>
</Equipment>
</Fields>
</Baseball>
How I need the output to look like:
<Baseball>
<Fields>
<Equipment>
<Bats>
<Bat Brand="Louisville" Model="16534" Length="34" Weight="30" Description="Composite" />
<Bat Brand="Easton" Model="asdfer" Length="32" Weight="29" />
</Bats>
</Equipment>
</Fields>
</Baseball>
I know I can solve this issue by writing to check the value but given the length of the transformation, I would like to avoid this if at all possible. In addition, give the structure of the XML that I will be drawing from, attributes for a given output node will have paths that differentiate from each other. For Example, the attribute "Brand" in the output node "Bat" might have a path of "ab/cd/ef/brand" while the attribute "Model" might have a path "ab/wx/yz/model". (I know my Baseball example above is not conducive to this point). Is there a way to achieve this without writing two XSLTs? Can you pass back through the output in XSLT?
No comments:
Post a Comment