Copied to clipboard

Flag this post as spam?

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


  • RoelAlblas 50 posts 61 karma points
    Oct 24, 2010 @ 14:15
    RoelAlblas
    0

    HTML from XML by XSL, render by XSLT

    Hi,

    I have a render XSLT that loads a XML that displays HTML based on the XML. That is working fine but rendering by getxmldocumentbyurl gives the pure XML while I like to have the HTML. What function should I use with XSL stylesheets in the XML?

    Thanks, Roel

    Render XSLT:

    <?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="/">
    <xsl:if test="$currentPage/data[@alias='gPXPicker'] &gt; 0">
     <xsl:variable name="gpxurl" select="umbraco.library:GetMedia($currentPage/data[@alias='gPXPicker'], 0)/data [@alias = 'umbracoGPX']"/>
     <xsl:if test="$gpxurl != ''">
      <xsl:variable name="xml" select="umbraco.library:GetXmlDocumentByUrl(concat('http://www.gpsblog.nl', $gpxurl))"/>
      <xsl:copy-of select="$xml" />
     </xsl:if>
    </xsl:if>

    </xsl:template>
    </xsl:stylesheet>

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Oct 24, 2010 @ 15:01
    Jan Skovgaard
    1

    Hi Roel

    It makes sense that the XML is returned. It's then up to you to transform it into HTML output.

    wrap a <textarea></textarea> around your <xsl:copy-of select="$xml" /> and copy/paste the rendered xml content into an editor where you can see the whole structure.

    Then you can easily see, which xpath you need to use to fetch the values you wan to show in your output html.

    I hope this makes sense?

    /Jan

  • RoelAlblas 50 posts 61 karma points
    Oct 24, 2010 @ 15:52
    RoelAlblas
    0

    Hi,

    Wouldnt't it be possible to use it like this in the XML:

    <?xml-stylesheet type="text/xsl" href="http://www.gpsblog.nl/scripts/GPX2GoogleMaps.xml" ?>

    So the stylesheet can transform the XML to HTML instead of using XPath. Is there a function in Umbraco to get the HTML generated by the XSL from XML.

    Roel

  • RoelAlblas 50 posts 61 karma points
    Oct 24, 2010 @ 20:48
    RoelAlblas
    0

    I removed the stylesheet from the XML and merged it in the render XML so I have got now one XSLT instead of two. The XSLT looks like below. At the moment I get a stackoverflow error in a javascript alertbox. It is at line 23 and that is the onload function in the body tag. The onload function is created by the XSLT. When I look in the source of the page I see the javascript rendered by the XSLT except the iteration through the GPX variable. Any suggestions?

     

    <?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:msxsl="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="/">
     <xsl:variable name="gpx">
      <xsl:if test="$currentPage/data[@alias='gPXPicker'] &gt; 0">
       <xsl:variable name="gpxurl" select="umbraco.library:GetMedia($currentPage/data[@alias='gPXPicker'], 0)/data [@alias = 'umbracoGPX']"/>
       <xsl:if test="$gpxurl != ''">
        <xsl:variable name="xml" select="umbraco.library:GetXmlDocumentByUrl(concat('http://www.gpsblog.nl', $gpxurl))"/>
        <xsl:copy-of select="$xml" />
       </xsl:if>
      </xsl:if>
     </xsl:variable>
     <script type="text/javascript">
     //&lt;![CDATA[
     function onLoad() {
      var map = new GMap(document.getElementById("map"));
      map.setMapType(G_HYBRID_MAP)
      map.addControl(new GSmallMapControl());
      map.addControl(new GMapTypeControl());
      var points = [];
      <xsl:for-each select="msxsl:node-set($gpx)/gpx/trk/trkseg/trkpt">
       <xsl:if test="position() = 1">
        map.centerAndZoom(new GPoint(<xsl:value-of select="@lon"/>, <xsl:value-of select="@lat"/> ), 5);
       </xsl:if>
       points.push(new GPoint(<xsl:value-of select="@lon"/>, <xsl:value-of select="@lat"/> ));
      </xsl:for-each>
      map.addOverlay(new GPolyline(points));
          }
     //]]&gt;
     </script>
    </xsl:template>
    </xsl:stylesheet> 
  • RoelAlblas 50 posts 61 karma points
    Oct 24, 2010 @ 21:55
    RoelAlblas
    0

    Solved! Take a look aty below, namespace issue. Google maps does not work yet but you can iterate through the gpx...

     

    <?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:gpx="http://www.topografix.com/GPX/1/1"
     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="/">
     <xsl:if test="$currentPage/data[@alias='gPXPicker'] &gt; 0">
      <xsl:variable name="gpxurl" select="string(umbraco.library:GetMedia($currentPage/data[@alias='gPXPicker'], 0)/data [@alias = 'umbracoGPX'])"/>
      <xsl:if test="$gpxurl != ''">
       <xsl:variable name="gpx" select="umbraco.library:GetXmlDocumentByUrl(string(concat('http://www.gpsblog.nl', $gpxurl)))"/>
       <script type="text/javascript">
        function onLoad() {
         var map = new GMap(document.getElementById("map"));
         map.setMapType(G_HYBRID_MAP)
         map.addControl(new GSmallMapControl());
         map.addControl(new GMapTypeControl());
         var points = [];
         <xsl:for-each select="$gpx/gpx:gpx/gpx:trk/gpx:trkseg/gpx:trkpt">
          <xsl:if test="position() = 1">
           map.centerAndZoom(new GPoint(<xsl:value-of select="@lon" disable-output-escaping="yes"/>, <xsl:value-of select="@lat" disable-output-escaping="yes"/> ), 5);
          </xsl:if>
          points.push(new GPoint(<xsl:value-of select="@lon" disable-output-escaping="yes"/>, <xsl:value-of select="@lat" disable-output-escaping="yes"/> ));
         </xsl:for-each>
         map.addOverlay(new GPolyline(points));
             }
     </script>
      </xsl:if>
     </xsl:if>
     </xsl:template>
    </xsl:stylesheet>
Please Sign in or register to post replies

Write your reply to:

Draft