Copied to clipboard

Flag this post as spam?

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


  • Andres Tenjo 35 posts 55 karma points
    Mar 25, 2011 @ 04:21
    Andres Tenjo
    0

    updating nodes from xslt ?

    Hi all ! 

    someone know how to update some value node in a document type using xslt ??


  • Pasang Tamang 258 posts 458 karma points
    Mar 25, 2011 @ 04:50
    Pasang Tamang
    0

    Hi Andres,

    You can do it by using c# coding and umbraco api within the xslt block. Here is an example about using c# and umbraco api within 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:visitTrack="urn:visitTrack"
            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="pageId" select="$currentPage/@id"/>
    <xsl:value-of select="visitTrack:updateVisit($pageId)"/>
    </xsl:template>
    <msxml:script language="C#" implements-prefix="visitTrack">
        <msxml:assembly href="../bin/cms.dll" />
        <msxml:assembly href="../bin/umbraco.dll" />
        <msxml:assembly href="../bin/businesslogic.dll" />
        <msxml:using namespace="umbraco.BusinessLogic" />
        <msxml:using namespace="umbraco.cms.businesslogic.web" />
        <msxml:using namespace="umbraco.cms.businesslogic.web" />
        public static string updateVisit(int pageId)
        {
            User author = User.GetUser(0); 
            Document doc = new Document(pageId);
            int getCount=int.Parse(doc.getProperty("visit").Value.ToString()) + 1;
            doc.getProperty("visit").Value = getCount.ToString();
            doc.Publish(author);
            umbraco.library.UpdateDocumentCache(doc.Id);
            return getCount.ToString();
        }
      </msxml:script>
    </xsl:stylesheet>

    Hope this helps you

    Pnima

     

  • Andres Tenjo 35 posts 55 karma points
    Mar 25, 2011 @ 23:08
    Andres Tenjo
    0

    thanks ! I'm using it !

  • Andres Tenjo 35 posts 55 karma points
    Mar 25, 2011 @ 23:28
    Andres Tenjo
    0

    I'm tying to apply for a quiz example but I couldn't fix this errorr....

    System.Xml.Xsl.XslLoadException: Prefix 'visitTrack' is not defined. An error occurred at

    I change visitTrack but what king of value or function can use ?



  • Pasang Tamang 258 posts 458 karma points
    Mar 26, 2011 @ 01:46
    Pasang Tamang
    0

    Changed all the "visitTrack" word? If you change the prefix from 

     

    <msxml:script language="C#" implements-prefix="visitTrack">

     

    then you have to change in 

     

    xmlns:visitTrack="urn:visitTrack"

     

    <xsl:value-of select="visitTrack:updateVisit($pageId)"/>

    Hope this helps

     

  • Andres Tenjo 35 posts 55 karma points
    Mar 27, 2011 @ 19:19
    Andres Tenjo
    0

    look at this error too :

    System.NullReferenceException: Object reference not set to an instance of an object.  

  • Andres Tenjo 35 posts 55 karma points
    Mar 27, 2011 @ 19:21
    Andres Tenjo
    0

    Please look my code to fix... 

    If you have another answer or option to dev this code please let me know...

     

      <xsl:param name="currentPage"/>

      <xsl:template match="/">

        <!-- start writing XSLT -->

        <script type="text/javascript">

          iSend = $("#content input[name=quiz]:checked").val();

        </script>

        <xsl:variable name="tmp">

          <xsl:value-of select="isend"/>

        </xsl:variable>

        <xsl:variable name="myvar" select="number($tmp)"/>

        <xsl:value-of select="visitTrack:updateVisit($myvar)"/>

      </xsl:template>

      <msxml:script language="C#" implements-prefix="visitTrack">

        <msxml:assembly href="../bin/cms.dll" />

        <msxml:assembly href="../bin/umbraco.dll" />

        <msxml:assembly href="../bin/businesslogic.dll" />

        <msxml:using namespace="umbraco.BusinessLogic" />

        <msxml:using namespace="umbraco.cms.businesslogic.web" />

        <msxml:using namespace="umbraco.cms.businesslogic.web" />

        public static string updateVisit(int myvar)

        {

        User author = User.GetUser(0);

        Document doc = new Document(myvar);

        int getCount=int.Parse(doc.getProperty("visit").Value.ToString()) + 1;

        doc.getProperty("visit").Value = getCount.ToString();

        doc.Publish(author);

        umbraco.library.UpdateDocumentCache(doc.Id);

        return getCount.ToString();

        }

      </msxml:script>

    </xsl:stylesheet>

Please Sign in or register to post replies

Write your reply to:

Draft