Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Tricky XSL xinclude question

Reply
Thread Tools

Tricky XSL xinclude question

 
 
rene
Guest
Posts: n/a
 
      04-29-2005
Hello everybody,

i have these 2 xml files

------1.xml------
<?xml version="1.0" encoding="UTF-8"?>
<root>
<element>1</element>
<element>2</element>
</root>
------end--------

------a.xml------
<?xml version="1.0" encoding="UTF-8"?>
<root>
<xi:include href="1.xml" xmlnsi="http://www.w3.org/2003/XInclude"
/>
<element>A</element>
<element>B</element>
</root>
------end--------

and want to have these output:
A1
B2
and so on...

Are there possibilities the get this output with nested for each? I've
also played with position() in one single foreach, but i cant get
these output.

Please can someone help me? I have no problem to get the output AB12
or with an manually xpath index.

Thanks a lot

René
 
Reply With Quote
 
 
 
 
David Carlisle
Guest
Posts: n/a
 
      04-29-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) (rene) writes:

> Hello everybody,
>
> i have these 2 xml files
>
> ------1.xml------
> <?xml version="1.0" encoding="UTF-8"?>
> <root>
> <element>1</element>
> <element>2</element>
> </root>
> ------end--------
>
> ------a.xml------
> <?xml version="1.0" encoding="UTF-8"?>
> <root>
> <xi:include href="1.xml" xmlnsi="http://www.w3.org/2003/XInclude"
> />
> <element>A</element>
> <element>B</element>
> </root>
> ------end--------
>
> and want to have these output:
> A1
> B2
> and so on...
>
> Are there possibilities the get this output with nested for each? I've
> also played with position() in one single foreach, but i cant get
> these output.
>
> Please can someone help me? I have no problem to get the output AB12
> or with an manually xpath index.
>
> Thanks a lot
>
> René


Your problem description is rather under-specified..

Firstly does your XML parse implement xinclude so that your xxslt
stylesheet if given a.xml on input actually sees
<?xml version="1.0" encoding="UTF-8"?>
<root>
<root>
<element>1</element>
<element>2</element>
</root>
<element>A</element>
<element>B</element>
</root>

or does it not implement xinclude in which case inputing a.xml will
just give you a tree corresponding to teh form you posted and 1.xml
would have to be accessed separately using the document() function?

When you say
> and want to have these output:
> A1
> B2


do you mean elements with those names, or elements with that content, or
just plain text, or what?

David



 
Reply With Quote
 
 
 
 
rene
Guest
Posts: n/a
 
      05-02-2005
Hi David,

> <?xml version="1.0" encoding="UTF-8"?>
> <root>
> <root>
> <element>1</element>
> <element>2</element>
> </root>
> <element>A</element>
> <element>B</element>
> </root>


your xml tree is right i can access the /root/root/element/, which
give me the "1". The problem is, i will do something like that:

<xsl:for-each select="root/element">
<tr>
<td><xsl:value-of select="."/></td> <!-- give me A and so on -->

<!-- Thats the big question: access the 1 and so on in the same loop
<td><xsl:value-of select="../../element"/></td>
-->

</tr>
</xsl:for-each>

I've try /root/root[position()]/element in the for-each loop, but this
wont work.

Best regards

Rene
 
Reply With Quote
 
rene
Guest
Posts: n/a
 
      05-02-2005
AHHH, I have it non sure if its a good way, but this gave me what i want

<xsl:for-each select="root/element">
<tr>
<td><xsl:value-of select="."/></td>
<xsl:variable name="i" select="position()"></xsl:variable>
<td><xsl:value-of select="/root/root/element[$i]"/></td>
<td><xsl:value-of select="document('1.xml')/root/element[$i]"/></td>
</tr>
</xsl:for-each>
</table>

your document question gives me also a helpful hint (thats looks better for me).

Rene
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tricky XSL transformation jl XML 3 08-23-2006 01:57 PM
a tricky if else(maybe not tricky but impossible) nirkheys@gmail.com C Programming 9 04-25-2006 06:13 PM
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
[xinclude] How to use indirection in xinclude like "Catalog" in the entity world ? SL XML 0 02-15-2005 01:58 PM
Tricky XSL question (?) Jyrki Keisala XML 4 01-05-2004 09:18 AM



Advertisments