how to apply xsl stylesheet only for a particaular tag

A

ashish.saket

Hi all,
H i have an xslt file which does some function say to suppress the
empty tags in complex elements.
for ex if i have an xml
<A>
<B>value</B>
<ReturnData>
<C1>value</C1>
<C2>value</C2>
<C3/>
</ReturnData>
<D>
<D1>value</D1>
<D2>value</D2>
<D3/>
</D>
<E>value</E>
</A>


now the o/p should be
<A>
<B>value</B>
<ReturnData>
<C1>value</C1>
<C2>value</C2>
</ReturnData>
<D>
<D1>value</D1>
<D2>value</D2>
<D3/>
</D>
<E>value</E>
</A>

basically we want to suppress any empty tags within <ReturnData> tag.
this <ReturnData> tag is common in all responses that we deal with
however the structure n the name of elements within <ReturnData> tag
varies with every response.
now we would like to have a generic xslt which we can apply to all the
response xmls
but it should suppress the empty tags within <ReturnData> tag only


regards
ashish
 
M

Martin Honnen

H i have an xslt file which does some function say to suppress the
empty tags in complex elements.
for ex if i have an xml
<A>
<B>value</B>
<ReturnData>
<C1>value</C1>
<C2>value</C2>
<C3/>
</ReturnData>
<D>
<D1>value</D1>
<D2>value</D2>
<D3/>
</D>
<E>value</E>
</A>


now the o/p should be
<A>
<B>value</B>
<ReturnData>
<C1>value</C1>
<C2>value</C2>

Start with the identity transformation template

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

then make sure that those empty child elements of ReturnData elements
are not processed further e.g.

<xsl:template match="ReturnData/*[not(node())]"/>
 
A

ashish.saket

Thanks Mr. Martin...

one more issue i am facing is that there can be many levels of nesting
inside the "ReturnData" element as shown below:
....
....
<ReturnData>
<C1>value</C1>
<C2>value</C2>
<C3/>
<C4>
<D1>value</D1>
<D2>value</D2>
<D3/>
<C4>
</ReturnData>
....

How to use the xsl code for this nesting mode?
 
M

Martin Honnen

one more issue i am facing is that there can be many levels of nesting
inside the "ReturnData" element as shown below:

Then
<xsl:template match="ReturnData//*[not(node())]"/>
instead of my ealier suggestion should do what you want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,255
Members
46,852
Latest member
CarlaDowle

Latest Threads

Top