Copied to clipboard

Flag this post as spam?

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


  • kashif 18 posts 38 karma points
    Nov 13, 2010 @ 18:18
    kashif
    0

    Custom XML not generating any output

    XML:

    <?xml version="1.0" encoding="utf-8"?>

    <DM TotalNodes="111">

    <product>

    <name>Hundred Dresses</name>

    </product>

    </DM>

    My 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: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" 
      xmlns:XMLMgr="urn:XMLMgr"
      xmlns:Utility="urn:Utility"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets XMLMgr Utility">
         


    <xsl:output method="html"/>
      
       
    <xsl:param name="currentPage"/>
     

     <xsl:template match="/">
      <xsl:variable name="XMLData" select="Utility:RemoveTroublesomeCharacters(XMLMgr:BinaryFileReader($url))" />     
     
    <apply-templates select="$XMLData//product" />      

         </xsl:template>
        <xsl:template match="product" >
        Product  Name: <xsl:value-of select="name" disable-output-escaping="yes" />
        </xsl:template>

    </xsl:stylesheet>

  • kashif 18 posts 38 karma points
    Nov 13, 2010 @ 18:20
    kashif
    0

    if i did this:

    <xsl:value-of select="$XMLData" />

    then it output the xml but when i try to apply the templates then it won't output anything ... why ? Did UMBRACO have their own XSLT standards ?

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Nov 13, 2010 @ 18:55
    Morten Bock
    0

    Something tells me that your XMLData variable just contains a string. If the <xsl:value-of actually outputs xml, then it does not contain a node set. If it was a nodeset, then <xsl:value-of would only writ out the values of the xslt, and not the tags.

    Two questions:

    1. Where do you set the $url variable? You seem to be using it, but I don't see it declared anywhere?

    2. What is going on inside your Utility:RemoveTroublesomeCharacters() and XMLMgr:BinaryFileReader() methods? What .Net type do they return?

     

  • kashif 18 posts 38 karma points
    Nov 13, 2010 @ 19:17
    kashif
    0

    Thanks for the reply.

    1) Since i just used it in a macro, so i have passed the url as a parameter , but right now i am using this simple code so that i can focus on the issue. For timebeing i am hardcoding the $url so now the updated fragmented is this. It still same no output. 

    Updated Code:

    <?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" 
      xmlns:XMLMgr="urn:XMLMgr"
      xmlns:Utility="urn:Utility"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets XMLMgr Utility">
         


    <xsl:output method="html"/>
      
       
    <xsl:param name="currentPage"/>
     

     <xsl:template match="/">

    <xsl:variable name="url" select="C:\abc.xml" />
      <xsl:variable name="XMLData" select="Utility:RemoveTroublesomeCharacters(XMLMgr:BinaryFileReader($url))" />     
     
    <apply-templates select="$XMLData//product" />      

         </xsl:template>
        <xsl:template match="product" >
        Product  Name: <xsl:value-of select="name" disable-output-escaping="yes" />
        </xsl:template>

    </xsl:stylesheet>

    2) BinaryFileReader: This function is reading the XML file from hard disk and returning XML as a string.

    RemoveTroublesomeCharacters: If i don't used this then i got the error System.ArgumentException: '.', hexadecimal value 0x00, is an invalid character. 

    so the above method is removing non UTF-8 Characters. I have 100's of these files and using in a asp.net 2.0 website without any problem,

    but something is different in Umbraco, that's why i wan'a know about that.


     

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Nov 13, 2010 @ 19:26
    Morten Bock
    0

    Try having both you methods returning an XPathNodeIterator instead of a string. Then XSLT will recognize it as being a node set.

    The 0x00 thing is a general thing with .Net, and not specific to umbraco. 0x00 is an invalid character in Xml, so the error is valid enough.

  • kashif 18 posts 38 karma points
    Nov 13, 2010 @ 19:50
    kashif
    0

    Yes, but the same code outside Umbraco work fine , means no 0x00.

    Actually i don't wan'a change my library code, as it's used in so many places. I have seen plenty of codes in this forum where people are not using node-set and it's working fine. I tried to used msxml:node-set in this scenario. But still no output. Is there any alternate without node-set ?

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Nov 13, 2010 @ 21:06
    Morten Bock
    0

    Ok, how about this:

    <?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"
                    xmlns:XMLMgr="urn:XMLMgr"
                    xmlns:Utility="urn:Utility"
                    xmlns:Helper="MyHelper"
                    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets XMLMgr Utility Helper">
    
      <xsl:output method="html"/>
      <xsl:param name="currentPage"/>
    
      <xsl:template match="/">
        <xsl:variable name="url" select="'C:\abc.xml'" />
        <xsl:variable name="XMLData" select="Helper:ConvertToXml(Utility:RemoveTroublesomeCharacters(XMLMgr:BinaryFileReader($url)))" />
        <xsl:apply-templates select="$XMLData//product" />
      </xsl:template>
    
      <xsl:template match="product" >
        Product  Name: <xsl:value-of select="name" disable-output-escaping="yes" />
      </xsl:template>
    
      <msxsl:script language="C#" implements-prefix="Helper">
        <![CDATA[
        public static XmlDocument ConvertToXml(string s){
          XmlDocument doc = new XmlDocument();
          doc.LoadXml(s);
          return doc;
        }
        ]]>
      </msxsl:script>
    </xsl:stylesheet>
    
    It sounds strange to me that you are using those same libraries in other sites that use xslt. But the above sample should show you how to get you string into a usable xml node-set that you can iterate.
  • kashif 18 posts 38 karma points
    Nov 14, 2010 @ 16:25
    kashif
    0

    Thank you, it's working now.

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Nov 14, 2010 @ 16:58
    Morten Bock
    0

    Glad it worked.

Please Sign in or register to post replies

Write your reply to:

Draft