[xsl] How to address generic unknown elements !

Subject: [xsl] How to address generic unknown elements !
From: Delaney Robin <Robin.Delaney@xxxxxxx>
Date: Thu, 14 Nov 2002 13:04:27 +0100
I have been using XML's with "known" element names that I could address but
I need to change it to be more generic so that I can 
run a stylesheet over an XML without knowing the structure beforehand:

XML:
	<ABC>
		<BCD>
			<EFG>
				<etc.....>
			</EFG>
		</BCD>
		<BCD>
			<EFG>
				<etc.....>
			</EFG>
		</BCD>
	</ABC>

old XSL:
	<xsl:template match="ABC">
		<xsl:for-each select="BCD[1]//*[not(*)]">	 
				<xsl:value-of select="local-name()"/>	
			</xsl:for-each> 
		</xsl:template>

	<xsl:template match="BCD">
		<xsl:for-each select=".//*[not(*)]">	 
			<xsl:value-of select="node()"/>	
 	 </xsl:template>

That gives me the drill down node-names from the first occurence of BCD and
the drill down node values of all BCD's.

I'm trying to have: (or similar!)
	<xsl:template match="/">
		<xsl:for-each select="?//*[not(*)]">	 ???stuck here???
			<xsl:value-of select="local-name()"/>	
		</xsl:for-each> 

		<xsl:for-each select=".//*[not(*)]">	 
			<xsl:value-of select="node()"/>	
 	  	</xsl:template>

My match is now "/"  (to process all) instead of ABC as I don't have
specific names to reference.

How do I reference BCD[1] (I know it always begins 2 levels down from the
top node) and drill down to the end of the node 1 time to get the node-names
without knowing it's name ? 

I only want it to do the local-name() piece once (ie. for the 1st element)
whilst doing node() for all elements. 

The node() bit is OK but I can't get the local-name() piece to deliver what
I want instead I end up with "number of iterations" x node-names. I guess
for-each is wrong but I think I'm stuck with 1 template match "/" or am I
thinking wrongly (again!).


Any help appreciated

Thanks,

Robin 



	


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


Current Thread