how to apply xsl stylesheet only for a particaular tag

Discussion in 'XML' started by ashish.saket@googlemail.com, Aug 31, 2006.

  1. Guest

    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
     
    , Aug 31, 2006
    #1
    1. Advertisements

  2. 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())]"/>
     
    Martin Honnen, Aug 31, 2006
    #2
    1. Advertisements

  3. Guest

    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?
     
    , Sep 1, 2006
    #3
  4. Then
    <xsl:template match="ReturnData//*[not(node())]"/>
    instead of my ealier suggestion should do what you want.
     
    Martin Honnen, Sep 1, 2006
    #4
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.