Copied to clipboard

Flag this post as spam?

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


  • Rob 43 posts 79 karma points
    Nov 22, 2012 @ 16:36
    Rob
    0

    Problem processing XML file

    I am not certain what is going on here. I am a bit of a NOOB when it comes to xlst so most likely it is somethign simple. I have tried to follow the example in this link umbraco.library:GetXmlDocumentByUrl for processing an xml file.

    The data I am using is KML data and seems to parse as valid XML. However when i run it through the xslt macro, all i get is a close ul tag e.g. </ul>

    Sample of the XML and XSLT below.

    And thank for any help in advance this one has been kicking my rear.

    *************KML/XSLT*********************

    <?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
    <Document>
    <name>Porter County Historic Resources Inventory</name>
    <gx:balloonVisibility>1</gx:balloonVisibility>
    <Style id="style601">
    <IconStyle>
    <Icon>
    <href>http://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png</href>;
    </Icon>
    </IconStyle>
    </Style>
    <Placemark>
    <name>127-406-01001</name>
    <description><![CDATA[<div dir="ltr">O<br>Wiebolt-Rostone House<br>208 Lake Front Drive<br>Modern<br>1933<br>Architecture<br>Architect: Walter Scholer</div>]]></description>
    <styleUrl>#style601</styleUrl>
    <Point>
    <coordinates>-87.002144,41.683964,0</coordinates>
    </Point>
    </Placemark>
    </Document>
    </kml>

    ***********XSLT MACRO*****************

    <?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="MyFeed" select="umbraco.library:GetXmlDocumentByUrl('http://localhost:20290/media/1283/kmltestsimple.xml')" />
    <ul>
    <xsl:for-each select="$MyFeed/kml/Document">
    <li>
    <xsl:value-of select="name" />
    </li>
    </xsl:for-each>
    </ul>
    </xsl:template>
    </xsl:stylesheet>

  • Rob 43 posts 79 karma points
    Nov 22, 2012 @ 18:02
    Rob
    0

    Ok.. I think i found the issue.

    2 things.

    I needed to remove the xmlns arguemnts - so the top tag was just <kml>
    and
    The KML has this line towards the top
    gx:balloonVisibility>1</gx:balloonVisibility>
    When I removed it, the node data became was returned!!  :D

    Much happier person now..
    Now all i need to do is pass the path to the KML (stored in the document via an upload datatype) into the macro as a paremeter.

    Rob

     

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 22, 2012 @ 19:46
    Chriztian Steinmeier
    1

    Hi Rob,

    Here's how to deal with namespaces (the xmlns thingies):

    The KML document defines a bunch of them - but the important one is the one with no prefix - copy that into your XSLT and assign it a prefix (I've used "k" in the code below) - now you can select and match any element in that namespace as well as anything else you would normally do. Here's a sample:

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umb="urn:umbraco.library"
        xmlns:k="http://www.opengis.net/kml/2.2"
        exclude-result-prefixes="umb k"
    >
    
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
    
        <!-- Grab URL from macro parameter -->
        <xsl:variable name="feedURL" select="/macro/feed" />
    
        <!-- Fetch document (you can put an extra cacheDuration argument) -->
        <xsl:variable name="feed" select="umb:GetXmlDocumentByUrl($feedURL)" />
    
        <xsl:template match="/">
            <ul>
                <xsl:apply-templates select="$feed/k:kml/k:Document" />
            </ul>
        </xsl:template>
    
        <!-- Template for a Document element in the KML namespace -->
        <xsl:template match="k:Document">
            <li>
                <xsl:value-of select="k:name" />
            </li>
        </xsl:template>
    
    </xsl:stylesheet>

    /Chriztian 

    EDIT: Trying to "fix" the formatting sometimes applied here. Hope it worked.

  • Rob 43 posts 79 karma points
    Nov 22, 2012 @ 20:21
    Rob
    0

    Chriztian I think you are pointing  me in the correct direction when it comes to the namespace bit. However when I tried your example I did bump into a problem with saving the doc

    Error occured

    System.UriFormatException: Invalid URI: The URI is empty.
    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
    at System.Uri..ctor(String uriString)
    at System.Net.WebRequest.Create(String requestUriString)
    at umbraco.library.GetXmlDocumentByUrl(String Url)

    This seems to be due to the parameter being used in the  GetXmlDocumentByUrl call. I had set up a macro parameter to use the url for the KML doc that was stored with the upload datatype in the doc. i.e./media/1329/porter.kml . The error seems to be the same as if i insert the relative path directly.

    Any idea as to how i can get around that?  

    Thanks in advance (and for the last post also!)

  • Rob 43 posts 79 karma points
    Nov 22, 2012 @ 21:18
    Rob
    0

    FOUND IT!! .

    The macro paremeter was (attempting )to read a property from the form. What was being appended to the url was the datatype name, not the value of what was stored in it.

    Soo. instead of trying to read the macro pareter, i just used the $currentpage/variablename syntax and things worked.
    Classic id10t error. Thanks for the help!!!

    Rob

     

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 22, 2012 @ 21:26
    Chriztian Steinmeier
    0

    Hi Rob,

    Great - I missed the fact that you we're using a saved KML file - but you found a way, which means you're already rockin' with Umbraco; Yay! :-)

    /Chriztian

  • Rob 43 posts 79 karma points
    Nov 22, 2012 @ 22:00
    Rob
    0

    I have looked at a number of different CMS systems in the past and feel really bad to have taken so long to find out about umbraco. This platform really rocks!

    I have been developing in .net since 1.0 and am very comfortable with pure code, and am also pretty fluent in css and html (love mvc) .. but as CMS systems go, most have left me intimidated. WIth the video tutorials here as a technology jumpstart and the pure flexiblitity of the platform, I am in love. I know that i still have a lot of learning to do and look forward to being able to put back into the comunity in the future.

    Thank you very much for all your help!

    Rob

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 22, 2012 @ 22:16
    Chriztian Steinmeier
    0

    You're welcome Rob - and I dig that you say these nice things on a post dealing with one of the hardest to grasp concepts of XML & XSLT (namespaces). You don't scare easy :-)

    Keep at it,

    /Chriztian

     

  • Rob 43 posts 79 karma points
    Nov 23, 2012 @ 19:35
    Rob
    0

    End result http://umb.lynchtek.com/gis-mapping/kml-test-2.aspx

    The xslt was used to generate a javascript array to populate the pushpins on a Bing maps control. (almost too easy when you get it right :) )

    XSLT to do it...

    <?xml version="1.0" encoding="utf-8" ?><xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:umb="urn:umbraco.library"
    xmlns:k="http://www.opengis.net/kml/2.2"
    exclude-result-prefixes="umb k">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    <xsl:param name="currentPage" />
    <!-- Grab URL from macro parameter -->
    <xsl:variable name="feedURL" select="concat('http://umb.lynchtek.com, $currentPage/kML)" />
    <!-- Fetch document (you can put an extra cacheDuration argument) -->
    <xsl:variable name="feed" select="umb:GetXmlDocumentByUrl($feedURL)" />

    <xsl:template match="/">
     <xsl:value-of select="k:name" />
     <script type='text/javascript'>
     
     var myArray = [
      <xsl:apply-templates select="$feed/k:kml/k:Document/k:Placemark" />  
      ]
      
     </script> 
    </xsl:template> 

    <!-- Template for a Document element in the KML namespace -->
    <xsl:template match="k:Document/k:Placemark">
    ['<xsl:value-of select="k:name" />','<xsl:value-of select="k:description" disable-output-escaping="yes" />','<xsl:value-of select="k:Point/k:coordinates"/>'],
    </xsl:template></xsl:stylesheet>

     

Please Sign in or register to post replies

Write your reply to:

Draft