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?
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.
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 ?
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.
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 " "> ]>
<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>
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 ?
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?
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 " "> ]>
<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.
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.
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 ?
Ok, how about this:
Thank you, it's working now.
Glad it worked.
is working on a reply...