Copied to clipboard

Flag this post as spam?

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


  • Christopher W. Brandsdal 72 posts 133 karma points
    Aug 31, 2009 @ 17:07
    Christopher W. Brandsdal
    0

    Issues with custom XSLT extention

    Hi, everyone!

    I have made an xslt extention in VS2008 that lists out some data from a weather-service I have. The XPathNodeIterator that is beeing returned from getNextPeriod() shows me this data when I run it as a test in VS:

    <perioddata>
      <windspeed>2,9</windspeed>
      <symbol>9</symbol>
      <temperature>9</temperature>
    </perioddata>

    But when I use it in my XSLT file, it returns "29" as windspeed, and NOT "2,9" as it should...

    <xsl:variable name="YRdata" select="KS.YR:getNextPeriod('http://www.someurl.com/somexml.xml')" />
    <xsl:template match="/">
    Vindstyrke: <xsl:value-of select="$YRdata//windspeed"/><br />
    SymbolID: <xsl:value-of select="$YRdata//symbol"/><br />
    Temperatur: <xsl:value-of select="$YRdata//temperature"/><br />
    </xsl:template>

    Anyone got any idea how to solve this?

    Best regards,
    ChristopherWB

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Aug 31, 2009 @ 17:26
    Peter Dijksterhuis
    100

    Its probably because it expects a . (dot) as decimal-separator and not a , (comma) (which is usually the thousand-separator)

    Try replacing the , with a . or change to the appropriate culture-settings.

    HTH,

    Peter

  • Christopher W. Brandsdal 72 posts 133 karma points
    Aug 31, 2009 @ 17:49
    Christopher W. Brandsdal
    0

    Hi, Peter!

    I changed to a ".", but I still get the same "error". My assembly now outputs:

    <perioddata>
      <windspeed>2.6</windspeed>
      <symbol>9</symbol>
      <temperature>10</temperature>
    </perioddata>
  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Aug 31, 2009 @ 19:58
    Morten Bock
    1

    Does it write out the correct xml if you use this in your macro:

    <xsl:copy-of select="$YRdata"/>

    Maybe try something like

    <xsl:value-of select="$YRdata/perioddata/windspeed" />

    You could also try wrapping your output in a CDATA field:

    <perioddata>
     
    <windspeed><![CDATA[2.6]]></windspeed>
     
    <symbol>9</symbol>
     
    <temperature>10</temperature>
    </perioddata>
  • Christopher W. Brandsdal 72 posts 133 karma points
    Aug 31, 2009 @ 21:02
    Christopher W. Brandsdal
    0

    Well, this is strange.. I added CDATA in my dll, but now it gives me this when I do a "copy-of":

    <perioddata>
    <windspeed>&lt;![CDATA[43]]&gt;</windspeed>
    <symbol>3</symbol>
    <temperature>12</temperature>
    </perioddata>

    Here is what my class returns when I set up a breakpoint in VS:

    <perioddata>
      <windspeed>&lt;![CDATA[4.3]]&gt;</windspeed>
      <symbol>3</symbol>
      <temperature>12</temperature>
    </perioddata>

    I have no idea where the "." or "," is going. This is so strange. Am I missing something here? Hehe.

  • Christopher W. Brandsdal 72 posts 133 karma points
    Aug 31, 2009 @ 21:04
    Christopher W. Brandsdal
    0

    Just for reference, here is my function i C#:

    public

     

    static XPathNodeIterator getNextPeriod(string YrXmlUrl)

    {

     

    XmlDocument xd = new XmlDocument();

    xd.LoadXml(

    "<perioddata />");

    KS.Weather.

    YR yr = new KS.Weather.YR();

     

    PeriodData pd = yr.NextPeriod(YrXmlUrl);

    #region

     

    xml situps

     

    // Windspeed

     

    XmlNode wind = xd.CreateElement("windspeed");

    wind.AppendChild(xd.CreateTextNode(

    string.Format("<![CDATA[{0}]]>", pd.Windspeed.ToString().Replace(",", "."))));

     

    // Symbol

     

    XmlNode symb = xd.CreateElement("symbol");

    symb.AppendChild(xd.CreateTextNode(pd.Symbol.ToString()));

     

    // multiply

     

    XmlNode temp = xd.CreateElement("temperature");

    temp.AppendChild(xd.CreateTextNode(pd.Temperature.ToString()));

    #endregion

    xd.DocumentElement.AppendChild(wind);

    xd.DocumentElement.AppendChild(symb);

    xd.DocumentElement.AppendChild(temp);

     

    return xd.CreateNavigator().Select(".");

    }

     

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Aug 31, 2009 @ 21:20
    Peter Dijksterhuis
    0

    Strange indeed....

    Does it return 43 in both situations? (with a dot and with a comma?)

  • Christopher W. Brandsdal 72 posts 133 karma points
    Aug 31, 2009 @ 21:23
    Christopher W. Brandsdal
    0

    Yes, it does. I have tried both ways. Somewhere from where the result is returned from my class to the result i rendered in XSLT, it removes bothe the comma and/or the dot.

  • Christopher W. Brandsdal 72 posts 133 karma points
    Aug 31, 2009 @ 21:56
    Christopher W. Brandsdal
    0

    How is this even possible? I changed my c# code to the following:

    // Windspeed
    XmlNode wind = xd.CreateElement("windspeed");
    string strWindspeed = pd.Windspeed.ToString().Replace(",", ".");
    wind.AppendChild(xd.CreateTextNode(strWindspeed + "."));

    I even tried to change "CreateTextNode" to "CreateCDataSection", but it makes do difference.

    now the output in debug is:

    <windspeed>4.3.</windspeed>

    and the XSLT outputs:

    <windspeed>43.</windspeed>
  • Tom Maton 387 posts 660 karma points
    Aug 31, 2009 @ 22:11
    Tom Maton
    0

    Hi Christopher

    Have you tried in your XSLT to specifiy the data type of the windspeed eg

    <xsl:template match="/">
    Vindstyrke:
    <xsl:value-of select="number($YRdata//windspeed)"/><br />
    SymbolID:
    <xsl:value-of select="$YRdata//symbol"/><br />
    Temperatur:
    <xsl:value-of select="$YRdata//temperature"/><br />
    </xsl:template>

    or

    <xsl:template match="/">
    Vindstyrke:
    <xsl:value-of select="string($YRdata//windspeed)"/><br />
    SymbolID:
    <xsl:value-of select="$YRdata//symbol"/><br />
    Temperatur:
    <xsl:value-of select="$YRdata//temperature"/><br />
    </xsl:template>

    Tom

  • Christopher W. Brandsdal 72 posts 133 karma points
    Aug 31, 2009 @ 22:17
    Christopher W. Brandsdal
    0

    Hi, Tom.

    Well, still the same when I change to string() or number(). I'm starting to think that I have to be getting something wront in the middle. Somehow the dot is not getting to the xslt from my extention. Is there any other properties I could be getting wrong?

  • Tom Maton 387 posts 660 karma points
    Aug 31, 2009 @ 22:38
    Tom Maton
    0

    I am guess that in the XML file itself looks fine? eg 4.3?

    Tom

  • Christopher W. Brandsdal 72 posts 133 karma points
    Aug 31, 2009 @ 22:49
    Christopher W. Brandsdal
    0

    Yes, my c# function that returns "return xd.CreateNavigator().Select(".");" produces the following result i Visual Studio XML Visualizer:

    ((System.Xml.DocumentXPathNavigator)(ngd).Current).InnerXml
    <perioddata>
      <windspeed>4.3</windspeed>
      <symbol>3</symbol>
      <temperature>12</temperature>
    </perioddata>

    So the function absolutely returns the windspeed "4.3".

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Aug 31, 2009 @ 23:22
    Morten Bock
    0

    What C# type is the windspeed in your PeriodData class?

    What happens if you just hardcode your C# method:

    xd.LoadXml("<perioddata><windspeed>4.3</windspeed>.....</perioddata>");
    

     

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Aug 31, 2009 @ 23:24
    Morten Bock
    0

    Have you also tried debugging the method by attaching the the IIS process to see if the result might be different when calling it from your website?

  • Christopher W. Brandsdal 72 posts 133 karma points
    Sep 01, 2009 @ 09:04
    Christopher W. Brandsdal
    0

    I finally figured it out! After a good night sleep, black coffee and a new approach I changed my code to the following:

    data.Windspeed = double.Parse(windspeed, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);

    With good help from all of you, especially Peter and Morten, I attached a local IIS to VS and it all came clear.

    Umb backend treets the culture different form frontend, so that's why I got conflicting results. Thanks to all of you!

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Sep 01, 2009 @ 11:08
    Peter Dijksterhuis
    0

    Glad you got it sorted :) Culture-info (and then especially decimal-separators and dates) can be a pain. Good to see my initial thought was the correct one ;)

Please Sign in or register to post replies

Write your reply to:

Draft