Tricky XSL xinclude question

R

rene

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" xmlns:xi="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é
 
D

David Carlisle

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" xmlns:xi="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
 
R

rene

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
 
R

rene

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top