Re: [xsl] Retrieving subelemets attributes & its text node data

Subject: Re: [xsl] Retrieving subelemets attributes & its text node data
From: "Joerg Heinicke" <joerg.heinicke@xxxxxx>
Date: Fri, 29 Mar 2002 13:58:13 +0100
Hello,

it's not so difficult. First you must select the correct spec-summary. I
easily applied templates to all known <spec-summary>s. If you want to have a
special one, you must change the first template, where the spec-summary is
selected.

The second step is selecting all descendant elements: descendant::*. The
rest is clear I think.

Regards,

Joerg

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:template match="part">
    <xsl:apply-templates select="spec-summary"/>
</xsl:template>

<xsl:template match="spec-summary">
    <xsl:apply-templates select="descendant::*"/>
</xsl:template>

<xsl:template match="*">
    <xsl:value-of select="name()"/>
    <xsl:apply-templates select="@*|text()"/>
</xsl:template>

<xsl:template match="@*">
    <xsl:if test="position() = 1">
        <xsl:text> </xsl:text>
    </xsl:if>
    <xsl:value-of select="name()"/>
    <xsl:text> = </xsl:text>
    <xsl:value-of select="."/>
    <xsl:text>&#10;</xsl:text>
</xsl:template>

<xsl:template match="text()">
    <xsl:value-of select="normalize-space(.)"/>
    <xsl:text>&#10;</xsl:text>
</xsl:template>

</xsl:stylesheet>

> Hi All,
>
> Is it possible to retrieve all the subelements its attributes & its text
> node data by simply knowing the root node name?
>
> I have an xml file like below:
>
>    <part name="TR1" category="TR">
>
>     <spec-summary>
>          <phase value="3" />
>          <transformation type="voltage">
>               <primary connection="wye">66000</primary>
>               <secondary connection="delta">6600</secondary>
>           </transformation>
>          <capacity unit="VA">5000000</capacity>
>          <cooling-method type="GNAN" />
>          <impedance type="%Z">7.5
>               <accuracy min="-10%" max="+10%" />
>          </impedance>
>     </spec-summary>
>
>   </part>
>
> By just knowing the part & spec-summary element names Can we retrieve all
> the subelements of
> spec-summary with attributes & text node data ?
> as :-
>
> > phase value = 3
> > transformation type = voltage
> > primary connection = wye
> > 66000
> > secondary connection = delta
> > 6600
> > capacity unit=VA
> > 5000000
> > cooling-method type = GNAN
> > impedance type = %Z
> > accuracy min = -10%
> > max = +10%
>
>
> Thanks for your time.
>
> Zulfakhar


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread