XSLT XML cleanup

M3mPh1z

Well-Known Member
Joined
Apr 26, 2008
Messages
469
Reaction score
11
Location
CPT
Hi Guys

I don't know XSLT and would like to use my current case to learn.

The case in question is multi level XML with many empty elements that I need to get rid of.

e.g.

Code:
<xml>
    <parent>
        <child>
            <toys>
                <toy colour="" type="" size="" />
                <toy colour="" type="" size="" />
                <toy colour="" type="" size="" />
                <toy colour="blue" type="sports" size="1kg" />
                <toy colour="" type="" size="" />
                <toy colour="" type="" size="" />
            </toys>
        </child>
        <Friend>
            <cars>
                <toy colour="white" make="Audi" model="A4" Year="2007" />
                <toy colour="" make="" model="" Year="" />
                <toy colour="" make="" model="" Year="" />
            </cars>
        </Friends>
    <parent>

What is the easiest method to do this? I think my two options would be matching a template (possibly multiple templates because of the structure) or copying the elements I want to keep.

Is there no way to farm through multi level xml to delete empty (of attributes and data) nodes?

If someone could link me to a tutorial that could help me do something like this it would be appreciated, I have been searching the net but cant quite find what I am looking for.

Thanks
 
Xpath will be your saving grace here. You don't need to define explicit paths here, but rather find all "toy" elements with empty attributes and just not select them. Only select the ones with data.
 
Top
Sign up to the MyBroadband newsletter
X