0

I've been digging into XSLT more and more these days but this issue has me scratching my head for the past few hours now.

I have the following XSLT script, it is used within a server environment to receive and help process part of a SOAP envelope.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:test="" exclude-result-prefixes="msxsl test">
<xsl:output method="xml" omit-xml-declaration="yes" indent="no"/>

    <msxsl:script implements-prefix="test" language="C#">
    public Param GetParam()
    {
        // Code here
    }
    </msxsl:script>

    <xsl:template match="/">

    <xsl:choose>

        <xsl:comment>Used by IT_E items</xsl:comment>

        <xsl:when test="helloworld">
            <xsl:text>helloworld|clientdata|username|</xsl:text>
            <xsl:value-of select="helloworld/clientdata/username"/>
            <xsl:text>$helloworld|clientdata|password|</xsl:text>
            <xsl:value-of select="helloworld/clientdata/password"/>
        </xsl:when>

Yes, only part of it. It would be too long and boring to post in full. Now, as you can see I have already prepared an msxsl block, however I have no clue how to proceed.

In short, what I want to achieve is to get my current output:

helloworld|clientdata|username|myvalue$helloworld|clientdata|password|myvalue

And then further processing, all done inside the XSLT script. Basically I would split on the $ character, then for each item in the array, split on | and fill a struct:

Param(string cmd, string class, string var, string val);

How can I return the Param object (my custom C# struct) instead of the plain text? Any hints to get me into the right direction?

Also, how does the custom prefix work? Can I just leave the URL empty in the declaration?


Update:

This is the XML I still have left from the SOAP envelope after processing by two other scripts that remove all SOAP elements from it.

<helloworld>
<clientdata>
    <username>test</username>
    <password>test</password>
<clientdata>

I should have included this from the start, my appologies!

  • Essentially, you can't. The MSXSL implementation (and most others as well) of XSLT 1.0 can only work with a small set of predefined datatypes (string, number, boolean, nodeset). If you got the C# code to recognize what a `Param` is and call that function, you would get an error like `Extension function parameters or return values which have Clr type 'Param' are not supported.` Perhaps if you told us what you are ultimately trying to achieve, we could help guide you. – JLRishe Jul 17 '13 at 17:04
  • @JLRishe Well, simply put, I wrote a server implementation and am receiving (at the moment) 3 different 'incoming message types': SOAP, JSON and a custom format. I want to process all 3 similair so I dont need to write 3 entirely different versions of my software, hence the struct part. I also want to try and keep it as simple and efficient as possible, hence I figured I'd be best to convert directly from script to my common struct. Perhaps far from the best idea. Any suggestions? –  Jul 17 '13 at 20:43
  • My suggestion would be to convert these input formats into a common XML structure and return that in the form of an XPathNavigator. That's what MSXSL knows how to work with, and XSLT is designed to process XML. – JLRishe Jul 18 '13 at 03:17

0 Answers0