Copied to clipboard

Flag this post as spam?

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


  • Marius 22 posts 42 karma points
    Oct 20, 2009 @ 08:48
    Marius
    0

    loading xml data

    Hi, I'm new to Umbraco, so my question might be very dumb.

    I have a xml file with structured data (people contact data, about 100 records).

    I need to load this data and output them in Umbraco page.

    Where to put this xml file in Umbraco directory structure?,
    and how do I load this file through Umbraco xslt

    I have already prepared a xslt file in VS:

    <asp:Xml id="xmlContacts" runat="server" DocumentSource="contacts.xml"></asp:Xml>

     

    Should I use ... GetXMLDocumentByUrl ?

    Thanks anyway,

    Marius

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Oct 20, 2009 @ 09:00
    Jan Skovgaard
    0

    Hi Marius

    Yes you should use the GetXmlDocumentByUrl extension to achieve your task. Then you can start parsing your XML file through XSLT and place the macro in your desired template.

    You could for instance place your XML file in a folder called "ExternalXML" or something like that and place it in the root.

    /Jan

  • Marius 22 posts 42 karma points
    Oct 20, 2009 @ 09:13
    Marius
    0

    Thanks for you answer, Jan.

    Can "url" parameter be a local url .. for example.. "/ExternalXML/xmlfile.xml" ?

    or a full web path like http://www.any.com/ExternalXML/xmlfile.xml

    that means I should change xslt's every time I change home domain...
    Chm.

    Thanks,
    Marius

  • Marius 22 posts 42 karma points
    Oct 20, 2009 @ 15:14
    Marius
    0

    A little update and more problems...

    Also you can get a local xml file on the same server by
    GetXMLDocument( Path, 1) 1 indicates here that it is relative path.

    But just can't figure out how to make this xslt work in Umbraco,

    my xml data:  http://www.lvat.lt:81/xmldata/struktura.xml

     what I don;t know here is - how to pass these path variables Kontakt to other templates, I need recursively process "Padalinys" template:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <!-- start writing XSLT -->
    <xsl:variable name="Kontakt" select="umbraco.library:GetXmlDocumentByUrl('http://www.lvat.lt:81/xmldata/struktura.xml')" />
    <xsl:variable name="KontaktLocal" select="umbraco.library:GetXmlDocument('/xmldata/struktura.xml', 1)" />
    <ul>
    <xsl:for-each select="$KontaktLocal/teismas/darbuotojai/padalinys">
    <li><xsl:value-of select="@caption"/></li>
    </xsl:for-each>
    </ul>
    <xsl:call-template name="Start">
    How to make template "Teismas" work?
    </xsl:call-template>
    <!-- End of writing XSLT -->
    </xsl:template>

    <xsl:template name="Start" match="teismas">
    <xsl:apply-templates select="pavadinimai/datos"/>
    <xsl:apply-templates select="darbuotojai/padalinys"/>
    </xsl:template>

    <xsl:template match="padalinys">
    <table class="kontaktai" summary="Teismo darbuotojų telefonų ir el.pašto adresų lentelė" >
    <caption>
    <xsl:value-of select="@caption"/>
    <xsl:if test="@pavadinimasid">
    <xsl:value-of select="//pavadinimas[@id=current()/@pavadinimasid]/@uzrasas"/>
    </xsl:if>
    <xsl:value-of select="@tel"/>
    </caption>
    <tr><th class="alignleft"><i><b>Vardas, pavardė</b></i></th>
    </tr>
    <xsl:apply-templates select="darbuotojas">
    <xsl:sort select="@order" data-type="number" order="ascending"></xsl:sort>
    <xsl:sort select="@pavarde" data-type="text" order="ascending"></xsl:sort>
    </xsl:apply-templates>
    </table>
    <br></br>
    <xsl:apply-templates select="padalinys"/>
    </xsl:template>
    <xsl:template match="darbuotojas">
    <!-- One data row -->
    <tr>
    <td class="alignleft">
    <xsl:value-of disable-output-escaping="yes" select="concat(@vardas,' &lt;b&gt;', @pavarde,'&lt;/b&gt;')"/>
    <xsl:if test="@pareigaid">
    ,<br/><span class="pareigos">
    <xsl:value-of select="//pareiga[@id=current()/@pareigaid]/@pavadinimas"/>
    </span>
    </xsl:if>
    </td>
    </tr>
    </xsl:template>

    <xsl:template match="datos">
    Atnaujinta: <div id="data">
    <xsl:value-of select="datalt/@data"/>
    </xsl:template>

    </xsl:stylesheet>

  • Chris Koiak 700 posts 2626 karma points
    Oct 20, 2009 @ 18:47
    Chris Koiak
    1

    Try something like

    <xsl:template match="/">
       <xsl:apply-templates select="$KontaktLocal/teismas"/>
    </xsl:template>

    <xsl:template match="teismas"> <!-- in replacement of Start -->
    <xsl:apply-templates select="pavadinimai/datos"/>
       
    <xsl:apply-templates select="darbuotojai/padalinys"/>
    </xsl:template>

     

  • Marius 22 posts 42 karma points
    Oct 21, 2009 @ 06:39
    Marius
    0

    Thanks man, works.

    Can't believe it was that simple.

    Yep, Smart things are simple.

    Marius.

Please Sign in or register to post replies

Write your reply to:

Draft