logo
down
shadow

Using C# in XSLT with MSXSL 6.0


Using C# in XSLT with MSXSL 6.0

By : Inji
Date : November 21 2020, 03:00 PM
I wish this helpful for you You won't be able to run C# code embedded in Xslt if you are using the msxsl processor. msxsl is using native Xml/Xslt processor which will not bootstrap CLR (managed runtime) for you. You can use vbscript/jscript inside msxsl:script when using the native Xml stack but C#/VB.NET can be used only with the managed Xslt processor (i.e. XsltCompiledTransform).
code :


Share : facebook icon twitter icon
Returning page numbers for a set of elements (optimisation for XSLT 1.0/msxsl)

Returning page numbers for a set of elements (optimisation for XSLT 1.0/msxsl)


By : sandy kris
Date : March 29 2020, 07:55 AM
around this issue This is not so much 'how do I do xxx' but 'how do I do xxx optimally?' (really hoping the challenge floats Dimitre's boat...) , Here is a solution using keys, which may be efficient:
code :
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:key name="kPage"
   match="chapter/title/processing-instruction('Page')"
   use="generate-id(..)"/>

 <xsl:key name="kPage"
   match="processing-instruction('Page')"
   use="generate-id(following::div[title][1]/title)"/>

 <xsl:template match="*">
  <xsl:apply-templates select=
   "*[1]|following-sibling::*[1]"/>
 </xsl:template>

 <xsl:template match="chapter/title[1] | div/title[1]">
  <meta>
    <field type="title"><xsl:value-of select="."/></field>
    <field type="page">
      <xsl:variable name="vPiText"
           select="key('kPage', generate-id())[last()]"/>
      <xsl:value-of select=
      "translate($vPiText,
                 translate($vPiText, '01234567890', ''),
                 ''
                 )"/>
    </field>

    <xsl:apply-templates select="*[1]|following-sibling::*[1]"/>
  </meta>
 </xsl:template>
</xsl:stylesheet>
<book>
    <chapter>
        <title>
            <?Page pageId="1"?>Chapter I</title>
        <div>
            <p>Introduction to Chapter</p>
            <p>Second paragraph 
                <?Page pageId="2"?>of introduction</p>
        </div>
        <div>
            <title>Section I</title>
            <p>A paragraph</p>
            <p>Another paragraph
                <?Page pageID="3"?></p>
        </div>
    </chapter>
    <chapter>
        <title>
            <?Page pageId="4"?>Chapter II</title>
        <div>
            <p>Introduction to Chapter</p>
            <p>...</p>
        </div>
    </chapter>
</book>
<meta>
   <field type="title">Chapter I</field>
   <field type="page">1</field>
   <meta>
      <field type="title">Section I</field>
      <field type="page">2</field>
   </meta>
</meta>
<meta>
   <field type="title">Chapter II</field>
   <field type="page">4</field>
</meta>
XSLT msxsl:format-date ignores current culture

XSLT msxsl:format-date ignores current culture


By : ExtremeCoder
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further If you omit the locale, then the XSLT defaults to the installation language of the XSLT processor you're using, the 1.0 one. (MS XSL Utility msxsl.exe or Visual Studio etc.) Doesn't matter what is the locale of the browser or your asp.net application.
In order to make it locale aware with least effort, you need to declare a variable (say with value "EN_us") and use it as the third parameter in all such date, time, number formatting functions.
How can I pass an absolute path via the command line to a parameter in XSLT 1.0 (using msxsl.exe)?

How can I pass an absolute path via the command line to a parameter in XSLT 1.0 (using msxsl.exe)?


By : Luis Osnet
Date : March 29 2020, 07:55 AM
like below fixes the issue It turns out that I just needed to set the string literals in single quotes (and the backslash did not need to be escaped). Also my srcroot has a trailing backslash, so I omitted it from the beginning here. Here is the updated code:
code :
<!-- Adapted from http://stackoverflow.com/a/30153713/5605122 and http://geekswithblogs.net/Erik/archive/2008/04/01/120915.aspx-->
<xsl:param name="srcroot" />
<xsl:variable name="filename">
    <xsl:call-template name="string-replace-all">
        <xsl:with-param name="text" select="concat($srcroot, 'foo/parts.xml')" />
        <xsl:with-param name="replace" select="'\'" />
        <xsl:with-param name="by" select="'/'" />
    </xsl:call-template>
</xsl:variable>
<!-- Adapted from https://www.stylusstudio.com/SSDN/default.asp?action=9&read=2993&fid=48 -->
<msxsl:script language="JScript" implements-prefix="user">
<![CDATA[
fso = new ActiveXObject("Scripting.FileSystemObject");
function fileExists(filename){
return fso.FileExists(filename);
}

// With .NET XSLT processor we need to use the Framework API
//function fileExists(filename){
//return System.IO.File.Exists(filename); 
//} 

]]>
</msxsl:script>
<xsl:if test="not( function-available('user:fileExists') )">
        <xsl:message terminate="yes">
            <xsl:text>Required facilities are not available.</xsl:text>
        </xsl:message>
</xsl:if>
<xsl:choose>
    <xsl:when test="user:fileExists(string($filename))">
        <xsl:message terminate="yes">
            <xsl:text>File found! Here:</xsl:text>
            <xsl:copy-of select="$filename"/>
        </xsl:message>
    </xsl:when>
    <xsl:otherwise>
        <xsl:message terminate="yes">
            <xsl:text>File cannot be found:</xsl:text>
            <xsl:copy-of select="$filename"/>
        </xsl:message>
    </xsl:otherwise>
</xsl:choose>
platformnotsupportedexception : XSLCompiledTransform.Load(xslt) not loading the xslt file with </msxsl:script> in

platformnotsupportedexception : XSLCompiledTransform.Load(xslt) not loading the xslt file with </msxsl:script> in


By : curiousmike
Date : March 29 2020, 07:55 AM
this one helps. According to the dotnet corefx github repository, the feature is not supported in .NET Core and there are currently no plans to implement it. More details can be found here
Unfortunately, it looks like your only option it to stick with .NET Framework for now.
code :
<xsl:template name="string-replace-all">
  <xsl:param name="text" />
  <xsl:param name="replace" />
  <xsl:param name="by" />
  <xsl:choose>
    <xsl:when test="contains($text, $replace)">
      <xsl:value-of select="substring-before($text,$replace)" />
      <xsl:value-of select="$by" />
      <xsl:call-template name="string-replace-all">
        <xsl:with-param name="text" select="substring-after($text,$replace)" />
        <xsl:with-param name="replace" select="$replace" />
        <xsl:with-param name="by" select="$by" />
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$text" />
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
<xsl:variable name="transform-relevant-part">
  <xsl:call-template name="string-replace-all">
    <xsl:with-param name="text" select="$relevant-part" />
    <xsl:with-param name="replace" select="$relevant-part" />
    <xsl:with-param name="by" select="$Pass_Bin_ASE_Code" />
  </xsl:call-template>
</xsl:variable>
<xsl:when test="contains($Pass_Bin_Codes, $relevant-part)">
msxsl:script for c# in xslt function declared twice error

msxsl:script for c# in xslt function declared twice error


By : isQuent
Date : March 29 2020, 07:55 AM
To fix this issue I ran your XSLT against a sample XML file and it ran well; this led me to believe you are probably calling this XSLT multiple times from other XSLT files.
The best way to handle this is that, if you have a root transform calling other transforms, to include it from there, so it is only referenced once; the aim is to ensure that the function is only included once throughout your transforms, otherwise you will encounter the error you are seeing.
Related Posts Related Posts :
  • ASP.NET MVC Html.BeginForm in WebGrid column
  • I need to set value of my ComboBox depending on selection of other ComboBox
  • How to get a result from a stored procedure as value?
  • Can I pass a ValueTuple to a method that requires a generic type and still maintain the member variables?
  • Testing eager-loading scenarios with Effort.EF6
  • Visual studio breaks on exception that IS handled with unhandled exception dialog
  • Cannot get property of class(ASP.NET MVC)
  • NUnit assertions in production code
  • Bug in SSRS CreateFolder C# command?
  • Convert web form content to PDF using c# in asp.net web forms
  • Web Application publishing failed - Visual Studio - C# - ASP.NET
  • How to encode IP for GET request in api in .NET
  • Access class item generated from xml using xsd.exe
  • Is there a shortcut to explicit named paramers when I call a method in C# for VisualStudio 2017?
  • Sorting datatables in a dataset with the datatable.name
  • Datagridview multilpe links
  • Correct pattern for exposing available actions
  • Local web application accepts numbers with comma and published does not
  • How to read an xml file using xmldataprovider in wpf C#
  • Windows service and Entity Framework
  • Visual Studio 2017 Docker support not available for ASP.Net Core Angular or React projects
  • Datacontext models with join
  • WPF: Increased window size decreases performance
  • Handling bad CSV records in CsvHelper
  • C# Displays file icons in asp.net on GridView nested
  • is there a way to get the file names which need to be updated if TFS status.Numoperations != 0?
  • Headless Firefox in Selenium C#
  • How do I start a .exe with a json string as parameter correctly?
  • StreamContent not loaded to the end
  • HAP parses formatting in HTML documents
  • repeat and count a loop in an unordered sequence in C#
  • Redundant Casting in Visual studio
  • Lost references in Visual Studio 2017 solution
  • Is there a way to add two numbers using a private constructor in C#
  • Is it possible to execute multiple SSH commands from a single login session with SSH.NET?
  • How can I get NHibernate to map to a Tuple or Class?
  • MVC 5 C# Window Authentication pop up when I navigate to a certain area
  • Mongo C# driver toJson() DateTime
  • Coprime integers
  • What is the purpose with files ending with *CS.cs in Xamarin Forms projects?
  • MVC5 / Entity | Update/Create Complex Model
  • How to return auto increment ID from SQL using Petapoco ORM in .NET MVC
  • Create new web app offline c# using Visual Studio
  • How many times is ordered the IEnumerable in this case?
  • C# error when update database 2008 to sql 2016
  • How to insert string in multiple continuous pattern in windows c#
  • How to send temp data from Partial View to its parent View
  • C# encapsulation when getting updates from asynchronous method
  • Asp net core Content Security Policy implementation
  • @Html.DropDownList() Placeholder as Disable and Selected
  • Set AM/PM in Material Time Picker WPF
  • Ninject passing reference in constructor
  • C# Entity Framework text SQL query wrapper
  • Core 2.0 MVC - AD Group Authorization for logging
  • Decentralized NLog Target per Http request
  • How to use x:Object and when?
  • Displays file icons in asp.net on GridView
  • How do I avoid two (or more) threads that work on a table at the same time to not work on same row?
  • Add xml attribute for property in DB First
  • How do i execute 2 sql queries by clicking a button [C#]
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org