xsl-list
[Top] [All Lists]

Re: Dynamical work with child nodes

2004-04-06 07:19:27
Depends on what you want to do - lots of possibilities.

Within your template:
<xsl:template match='row'> <!-- or however you select your <row> elements --> <xsl:apply-templates select='*'/> <!-- to exclude immediate child TEXT nodes - no select needed to include them --> <!-- you need to have templates defined to match the respective child elements occurring -->
<!-- OR -->
<xsl:for-each select='*'> <!-- to explicitly process them - e.g. sorted on their names -->
   <xsl:sort order='ascending' data-type='text' use='name()'/>
<!--
... whatever you want to do
... even
   <xsl:if test='name() = 'id'>....</xsl:if>
-->
   </xsl:for-each>
<!-- OR to call specialised templates to just process the ones you want -->
<xsl:call-template name='magic-stuff'>
   <xsl:with-param name='IDS' select='id'/>
</xsl:call-template>
</xsl:template>

Not sure if this helps or not (NSITHON).

Roland Juergens wrote:

Hi,

I have an XML file like this which contains results from a database query.
Is there a way to go dynamically through the subelements of my "row"
elements, because I want to use it for different queries.
So the subelements like "id" or "name" might change.

<root>
        <rowset>
                <row>
                        <id>1</id>
                        <name>bla</name>
                </row>
                <row>
                        <id>2</id>
                        <name>blabla</name>
                </row>

                ...(more <row> elements)...

        </rowset>
</root>


This is how the xsl-file looks like now

...
<xsl:for-each select="root/rowset/row">
...
        <xsl:value-of select="id"/>
...
        <xsl:value-of select="name"/>
...
</xsl:for-each>
...



What I imagine is the following :
I want to get the number of subelements of a "row" element, then iterate
over it to get the names, and then building it dynamical.
Is something like that possible ?


Roland Juergens



--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--

--
Datalucid Limited
8 Eileen Road
South Norwood
London SE25 5EJ
/ tel :0208-239-6810
mob: 0794-725-9760
email: mike(_dot_)trotman(_at_)datalucid(_dot_)com
/
UK Co. Reg:     4383635
VAT Reg.:       798 7531 60




<Prev in Thread] Current Thread [Next in Thread>