Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Claushingebjerg 886 posts 2415 karma points
    Sep 01, 2010 @ 16:46
    Claushingebjerg
    0

    traversing external xml file

    Im using an externale xml file as a data source, but having trouble getting the data i need in thye right order...

    my source is as follows:

     


    <xsl:variable name="kulturkalender">myfile.xml</xsl:variable>

    <xsl:template match="/">
    <xsl:variable name="kalender" select="umbraco.library:GetXmlDocumentByUrl($kulturkalender, 50000)" />
     

      <ul>
        <xsl:apply-templates select="$kalender//arrs" />
      </ul>

    </xsl:template>

    <xsl:template match="arrs">
    <xsl:if test="position() &lt;= 100">
      <li >
        <xsl:value-of select="@genre"/><br/>
        <strong><xsl:value-of select="arr/kunstner"/></strong>
        </li>
    </xsl:if>
    </xsl:template>

     


    My xml is as follows:

     <arrlist>
          <arrs genre="Musik">
             <arr ArrNr="4640717">
                <kunstner>Torsdagskoncerter på Østergade, Herning.</kunstner>
             </arr>
             <arr ArrNr="4743104">

                <kunstner>Jens Christian Wandt på Hjerl Hede.</kunstner>        
    </arr>

    </arrs>
    </arrlis>

     

     

    What im looking to get is list the "@genre" on every "arr" so it lists like:

     

    <ul>
    <li>Musik<br/>Torsdagskoncerter på Østergade, Herning</li>
    <li>Muisk<br/>Jens Christian Wandt på Hjerl Hede.</li>
    </ul>

     


  • Claushingebjerg 886 posts 2415 karma points
    Sep 01, 2010 @ 16:46
    Claushingebjerg
    0

    im on 4.5.1 by the way

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Sep 01, 2010 @ 16:55
    Dirk De Grave
    0

    Have you tried using the full url to the xml file? Even if it's on the local server, I think you need to specify an url as the function does perform a WebRequest.

    If that doesn't help, you can always output the error that gets returned from the function.

     

    Error xml returned in case of exception is

    <error url="url">error</error>

    where url is the parameter fed to the function and the error is the error message returned from the exception (if it has occured)

    Hope this helps.

    Regards,

    /Dirk

  • Claushingebjerg 886 posts 2415 karma points
    Sep 01, 2010 @ 17:22
    Claushingebjerg
    0

    Sorry for not being clear.

    I typed my example as compact as possible...

    my real url to the xml is a full url, i just didnt want to post it here. Im getting data out of it ok. 

    I'm just unable to get the "genre" attribute rendere in each <li>

     

    Hope this makes sense. 

  • Steen Tøttrup 191 posts 291 karma points c-trib
    Sep 01, 2010 @ 17:26
    Steen Tøttrup
    1

    I'll try and beat Chriztian to it, and he'll probably be around later to come up with a much better solution.

    I assume the problem isn't getting the xml, if it is, take a look at what Dirk has written.

    So try this (this is done off the top of my head, so I haven't tested it):


     <xsl:apply-templates select="$kalender//arrlist/arrs" />
    </xsl:template>

    <
    xsl:template match="arrs">
     <xsl:if test="position() &lt;= 100">
      <ul>
       
    <xsl:apply-templates select="arr" />
      </ul>
     </xsl:if>
    </xsl:template>

    <xsl:template match="arr">
     
    <li><xsl:value-of select="../@genre" /><br /><xsl:value-of select="kunstner" /></li>
    </xsl:template>

    I'm not sure what sort order you want the result in ?!

  • Claushingebjerg 886 posts 2415 karma points
    Sep 01, 2010 @ 17:31
    Claushingebjerg
    0

    Works like a charm, Thanks

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Sep 01, 2010 @ 22:12
    Chriztian Steinmeier
    0

    Ha ha - good one, Steen :-)

    /Chriztian

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies