Renaming XML tags if no attributes

Here should go questions about transforming XML with XSLT and FOP.
janpad
Posts: 2
Joined: Wed Aug 12, 2009 8:16 am

Renaming XML tags if no attributes

Post by janpad »

Hi.

Does any one know if there is a way to rename an opening and its corresponding closing tag if it has no attributes, in XSLT.

For example –
<SampleTag>
<Innertag/>
</SampleTag>

I need to rename <SampleTag> to <OuterTag> and </OuterTag> as <SampleTag> does not have attributes.
Any help would be greatly appreciated.

Regards,
Jan
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Renaming XML tags if no attributes

Post by sorin_ristache »

Hello,

It can be renamed with a template like the following:

Code: Select all

  <xsl:template match="SampleTag">
<OuterTag>
<xsl:apply-templates/>
</OuterTag>
</xsl:template>
You should read an XSLT tutorial.


Regards,
Sorin
janpad
Posts: 2
Joined: Wed Aug 12, 2009 8:16 am

Re: Renaming XML tags if no attributes

Post by janpad »

Thanks a lot for your reply Sorin.
Can you please let me know how to check if an attribute exists or not for a tag and then carry out this XSLT?

Regards,
Jan
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Renaming XML tags if no attributes

Post by sorin_ristache »

Please read an XSLT tutorial here or here and do some XSLT examples included in a tutorial.


Regards,
Sorin
Post Reply