Domanda

I am trying to use escape charaters in my text output, as i would like too surround the output in emailData tags. I am using

<xsl:text>&#60;emailData&#62;</xsl:text>

In the XSLT to esnure that this works however because i am using a tool called Cast Iron for some reason it is not converting the &#60; into < and just spits out &lt;emailData>

You can see am image of it HERE that illustrates the output i am getting. My source code is this. How else could i wrap this in emailData tags?

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text"/>

    <xsl:template match="header">
        <xsl:text>&#60;emailData&#62;</xsl:text>
        <xsl:text>&#10;</xsl:text>
        <xsl:text>From: </xsl:text>
        <xsl:value-of select="from/text()"/>
        <xsl:text>&#10;</xsl:text>
        <xsl:text>To: </xsl:text>
        <xsl:value-of select="to/text()"/>
        <xsl:text>&#10;</xsl:text>
        <xsl:text>Subject: </xsl:text>
        <xsl:value-of select="subject/text()"/>
        <xsl:text>&#10;</xsl:text>
        <xsl:text>Content-Type: </xsl:text>
        <xsl:value-of select="contentType/text()"/>
        <xsl:text>&#10;</xsl:text>
        <xsl:text>  boundary="</xsl:text>
        <xsl:value-of select="boundary/text()"/>
        <xsl:text>"</xsl:text>
        <xsl:text>&#10;</xsl:text>
        <xsl:text>MIME-Version: </xsl:text>
        <xsl:value-of select="mimeVersion/text()"/>
    </xsl:template>

    <xsl:template match="email">
        <xsl:text>&#10;&#10;</xsl:text>
        <xsl:text>--</xsl:text>
        <xsl:value-of select="../header/boundary/text()"/>
        <xsl:text>&#10;</xsl:text>
        <xsl:text>Content-Type: </xsl:text>
        <xsl:value-of select="contentTypeBody/text()"/>
        <xsl:text> charset="us-ascii"</xsl:text>
        <xsl:text>&#10;</xsl:text>
        <xsl:text>Content-Transfer-Encoding: </xsl:text>
        <xsl:value-of select="contentTransfer/text()"/>
        <xsl:text>&#10;&#10;</xsl:text>
        <xsl:value-of select="body/text()"/>
    </xsl:template>

    <xsl:template match="Attachment">
        <xsl:for-each select="Attachments">
            <xsl:text>&#0010;&#0010;</xsl:text>
            <xsl:value-of select="../../header/boundary/text()"/>
            <xsl:text>&#10;</xsl:text>
            <xsl:text>Content-Type: </xsl:text>
            <xsl:value-of select="attachmentContentType/text()"/>
            <xsl:text> name="</xsl:text>
            <xsl:value-of select="attachmentDescription/text()"/>
            <xsl:text>"</xsl:text>
            <xsl:text>&#10;</xsl:text>
            <xsl:text>Content-Description: </xsl:text>
            <xsl:value-of select="attachmentDescription/text()"/>
            <xsl:text>&#10;</xsl:text>
            <xsl:text>Content-Disposition: attachment; filename="</xsl:text>
            <xsl:value-of select="atachementDisposition/text()"/>
            <xsl:text>"</xsl:text>
            <xsl:text>&#10;</xsl:text>
            <xsl:text>Content-Transfer-Encoding: </xsl:text>
            <xsl:value-of select="attachmentContentTransfer/text()"/>
            <xsl:text>&#10;&#10;</xsl:text>
            <xsl:value-of select="attachementBody/text()"/>
            <xsl:text>&#10;</xsl:text>
            <xsl:text>&#60;/emailData&#62;</xsl:text>
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="text()"/>

</xsl:stylesheet>
È stato utile?

Soluzione

I would generate XML directly rather than XML-encode text so

change

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text"/>

    <xsl:template match="header">
        <xsl:text>&#60;emailData&#62;</xsl:text>

to

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml"/>

   <xsl:template match="/"><emailData><xsl:apply-templates/></emailData></xsl:template>

    <xsl:template match="header">
       <!-- <xsl:text>&#60;emailData&#62;</xsl:text>-->

Altri suggerimenti

add disable-output-escaping="yes" to your <xsl:text> elements:

<xsl:text disable-output-escaping="yes">&#60;...&#62;</xsl:text>

will show up as

<...>

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top