xml - xslt boolean aggregation of a children property -
i aggregate boolean value exists in children of node , add parent. xml document looks like:
<?xml version="1.0" encoding="utf-8"?> <module> <entity name="test" > <attributes name="att1" translatable="true"> <attributes name="att2" translatable="false"> <attributes name="att3" translatable="false"> <attributes name="att4" translatable="true"> </attributes> </entity> </module>
and transform to:
<?xml version="1.0" encoding="utf-8"?> <module> <!-- @ entity level property translatable shall result of or aggregation of children attributes.translatable i.e. iterate attributes (true or false or false or true = true ) ==> entity.translatable=true --> <entity name="test" translatable="true"> <attributes name="att1" translatable="true"> <attributes name="att2" translatable="false"> <attributes name="att3" translatable="false"> <attributes name="att4" translatable="true"> </attributes> </entity> </module>
iterate attributes (true or false or false or true = true ) ==> entity.translatable=true
there no need iterate - need ask if there @ least 1 attribute value of true:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/> <!-- identity transform --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="entity"> <entity name="{@name}" translatable="{boolean(attribute[@translatable='true'])}" > <xsl:apply-templates/> </entity> </xsl:template> </xsl:stylesheet>
the above assumes well-formed xml input such as:
<module> <entity name="test"> <attribute name="att1" translatable="true"/> <attribute name="att2" translatable="false"/> <attribute name="att3" translatable="false"/> <attribute name="att4" translatable="true"/> </entity> </module>
Comments
Post a Comment