I have to get the attribute names and do some manipulations based on the its name in XSLT.
Source:
<group xlink:type="simple" xlink:href="XXX" xlink:title="sectionHeader_1" xmlns:xlink="http://www.w3.org/1999/xlink"></group>
<group xlink:type="simple" xlink:href="YYY" xlink:title="BodyParagraph_1" xmlns:xlink="http://www.w3.org/1999/xlink"></group>
<group xlink:type="simple" xlink:href="ZZZ" xlink:title="sectionHeader_2" xmlns:xlink="http://www.w3.org/1999/xlink"></group>
<group xlink:type="simple" xlink:href="AAA" xlink:title="sectionHeader_3" xmlns:xlink="http://www.w3.org/1999/xlink"></group>
<group xlink:type="simple" xlink:href="BBB" xlink:title="BodyParagraph_2" xmlns:xlink="http://www.w3.org/1999/xlink"></group>
<group xlink:type="simple" xlink:href="BBB" xlink:title="ConditionalText_2" xmlns:xlink="http://www.w3.org/1999/xlink"></group>
I have to get the attribute xlink:title attribute in it and check for the following:
- when the attribute xlink:title contains string sectionHeader , I need to do some manipulations.
- when the attribute xlink:title contains string BodyParagraph, I need to some manipulations.
- when the attribute xlink:title contains string ConditionalText, I need to some manipulations.
Can any one explain how it can be done?
It is in the spirit of XSLT to use templates and pattern matching so that explicit conditional instructions are minimized or eliminated altogether.
Here is how this can be done:
When this transformation is applied on the provided XML fragment (converted to a well-formed XML document):
the wanted result (something done in each case) is produced:
Do note: You may consider using the
starts-with()function rather thancontains().