Tricky XSL xinclude question

Discussion in 'XML' started by rene, Apr 29, 2005.

  1. rene

    rene Guest

    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é
     
    rene, Apr 29, 2005
    #1
    1. Advertising

  2. (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" 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
     
    David Carlisle, Apr 29, 2005
    #2
    1. Advertising

  3. rene

    rene Guest

    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
     
    rene, May 2, 2005
    #3
  4. rene

    rene Guest

    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
     
    rene, May 2, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jyrki Keisala

    Tricky XSL question (?)

    Jyrki Keisala, Jan 2, 2004, in forum: XML
    Replies:
    4
    Views:
    468
    Jyrki Keisala
    Jan 5, 2004
  2. SL
    Replies:
    0
    Views:
    545
  3. Replies:
    1
    Views:
    3,689
    A. Bolmarcich
    May 27, 2005
  4. jl
    Replies:
    3
    Views:
    431
    Andy Dingley
    Aug 23, 2006
  5. Replies:
    9
    Views:
    561
    CBFalconer
    Apr 25, 2006
Loading...

Share This Page