This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: merging generic elements in a parent-child relationship Part II


I've solved both problems!
I did this for the param problem
<xsl:apply-templates select="//*[name()=$TopElement]"/>
so this will choose all the elements whose name is stored in TopElement
and the id problem
I added a variable currentTag
<xsl:variable name="currentTag" select="name()"/>
...
<xsl:apply-templates
select="../*[@*[name()=concat('id',$currentTag)]=current()/@id]"/>

But I have a question now...
I have the XML transformed like this

<?xml version="1.0" encoding="UTF-8"?>
<root>
	<Persona id="abc" idCountry="1">
		<b id="b1" idPersona="abc"></b>
		<b id="b2" idPersona="abc"></b>
		<c id="c1" idb="b1" idPersona="abc">
		</c>
	</Persona>
	<Persona id="abcd" idCountry="1">
		<b id="b3" idPersona="abcd">
		</b>
	</Persona>
</root>

I want to wrap each collection of elements into other element. Like this

<?xml version="1.0" encoding="UTF-8"?>
<root>
	<PersonaGroup>
		<Persona id="abc" idCountry="1">
			<bGroup>
				<b id="b1" idPersona="abc"></b>
				<b id="b2" idPersona="abc"></b>
			</bGroup>
			<cGroup>
				<c id="c1" idb="b1" idPersona="abc"></c>
			</cGroup>
		</Persona>
		<Persona id="abcd" idCountry="1">
			<bGroup>
				<b id="b3" idPersona="abcd"></b>
			</bGroup>
		</Persona>
	</PersonaGroup>
</root>

thanks!

ps: Dimitre thanks for answering... actually I've already solved it in a
similar way... do you know the last question?

Matias


> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of Matias
> Woloski
> Sent: jueves, 27 de junio de 2002 14:47
> To: xsl-list@lists.mulberrytech.com
> Subject: [xsl] merging generic elements in a parent-child relationship
> Part II
>
>
> Hi guys!
> thanks for the help and the stylesheets :)
>
> Right now I've decided to go for the most simple one and began to
> make some
> modifications to suit my needs
>
> The XML is this one:
> <root>
> 	<Persona id="abc" idCountry="1"/>
> 	<Persona id="abcd" idCountry="1"/>
> 	<b id="b1" idPersona="abc"/>
> 	<b id="b2" idPersona="abc"/>
> 	<b id="b3" idPersona="abcd"/>
> 	<c id="c1" idb="b1"/>
> </root>
>
> This is the stylesheet I have. Note the TopElement param. This is
> something
> I'm gonna know.
>
> 1 <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> 2	<xsl:output method="xml" version="1.0" encoding="UTF-8"
> indent="yes"/>
> 3	<xsl:param name="TopElement" select="Persona" />
> 4 <xsl:template match="root">
> 5   <root>
> 6     <xsl:apply-templates select="//Persona"/>
> 7   </root>
> 8 </xsl:template>
> 9
> 10  <xsl:template match="*">
> 11   <xsl:element name="{name()}">
> 12     <xsl:copy-of select="@*"/>
> 13     <xsl:apply-templates select="../*[@idPersona=current()/@id or
> @idb=current()/@id]"/>
> 14   </xsl:element>
> 15  </xsl:template>
> 16 </xsl:stylesheet>
>
> There are some things I would like to know
> 1. Line 6. How can I select based on the TopElement param. I would like to
> do something like
> <xsl:apply-templates select="//$TopElement" />
>
> 2. Line 13. I'd like to make this on runtime. I mean, instead of having
> @idPersona I'd like to have @concat('id',name()). obviously this cannot be
> done. Is this possible to do? I've read the Things XSL can't do on
> http://www.dpawson.co.uk and there is one that maybe answer my questions
>
> "...There is no way in XSLT of constructing XPath expressions
> (e.g. variable
> references) at run-time..."
>
> So if this is true, I'm looking for a workaround on this...
>
> thanks for your help,
> Matias
>
>
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]