[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Get nodes with document() and applying templates to th

Subject: Get nodes with document() and applying templates to them
From: António Mota <amsmota@xxxxxxxxx>
Date: Mon, 14 Feb 2005 14:03:28 +0000
xml get nodes
Hi again:

I'm trying to do something like this:

Given

<Menu>
	<Menu_K>X00123</Menu_K>
	<MenuData/>
	<MenuTipo>TXT</MenuTipo>
	<MenuTitulo>Ambitos</MenuTitulo>
	<Menu>
		<Menu_K>X00124</Menu_K>
		<MenuData>X00125</MenuData>
		<MenuTipo>REP</MenuTipo>
		<MenuTitulo>(...)</MenuTitulo>
	</Menu>
</Menu>

and another XML similar (actually it can be the same)

<Menu>
	<Menu_K>X00125</Menu_K>
	<MenuData/>
	<MenuTipo>TXT</MenuTipo>
	<MenuTitulo>Sub-Ambitos</MenuTitulo>
	<Menu>
		<Menu_K>X00126</Menu_K>
		<MenuData/>
		<MenuTipo>TXT</MenuTipo>
		<MenuTitulo>Sub-Sub-Ambitos</MenuTitulo>
	</Menu>
</Menu>

i want to apply a identity transform that simply replaces the REP
menus with the menu whose K is defined on MenuData, so in the example
i'll get


<Menu>
	<Menu_K>X00123</Menu_K>
	<MenuData/>
	<MenuTipo>TXT</MenuTipo>
	<MenuTitulo>Ambitos</MenuTitulo>
	<Menu>
		<Menu_K>X00125</Menu_K>
		<MenuData/>
		<MenuTipo>TXT</MenuTipo>
		<MenuTitulo>Sub-Ambitos</MenuTitulo>
		<Menu>
			<Menu_K>X00126</Menu_K>
			<MenuData/>
			<MenuTipo>TXT</MenuTipo>
			<MenuTitulo>Sub-Sub-Ambitos</MenuTitulo>
		</Menu>
	</Menu>
</Menu>

I've done this

	<xsl:template match="Menu">
		<xsl:choose>
			<xsl:when test="MenuTipo='REP'">

				<xsl:apply-templates
select="document('TreeMenu.xml')//Menu[Menu_K=current()/MenuData]/Menu"
/>

			</xsl:when>
			<xsl:otherwise>
				<xsl:copy>
					<xsl:apply-templates select="*"/>
				</xsl:copy>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

wich is working OK, *unless* in the second XML i have also REP menus.
In that case the REP menus on the second tree are just ignored, nor
are copyed nor REPlaced.

What i was hoping to get is the replaced menus, everywere. That is why
i'm using apply-templates instead of copy-of, tath copys the entire
second tree but withou replacing the REP's.

What am i doing wrong in here?

Thanks.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.