Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
822 views
in Technique[技术] by (71.8m points)

xslt 1.0 - How can I embed a xsl:value-of result into a CDATA block?

I have this snippet in my XSL file:

<script type="text/javascript">
    <![CDATA[
    function clearSelection() {
        if (document.getSelection) { // for all new browsers (IE9+, Chrome, Firefox)
            document.getSelection().removeAllRanges();
            document.getSelection().addRange(document.createRange());
            console.log("document.getSelection");
        } else if (window.getSelection) { // equals with the document.getSelection (MSDN info)
            if (window.getSelection().removeAllRanges) { // for all new browsers (IE9+, Chrome, Firefox)
                window.getSelection().removeAllRanges();
                window.getSelection().addRange(document.createRange());
                console.log("window.getSelection.removeAllRanges");
            } else if (window.getSelection().empty) { // Chrome supports this as well
                window.getSelection().empty();
                console.log("window.getSelection.empty");
            }
        } else if (document.selection) { // IE8-
            document.selection.empty();
            console.log("document.selection.empty");
        }
    }
    function CopyToClipboard(containerid) {
        clearSelection();
        if (document.selection) {
            var range = document.body.createTextRange();
            range.moveToElementText(document.getElementById(containerid));
            range.select().createTextRange();
            document.execCommand("copy");
        } else if (window.getSelection) {
            var range = document.createRange();
            range.selectNode(document.getElementById(containerid));
            window.getSelection().addRange(range);
            document.execCommand("copy");
            alert("The assignment slip has been copied, now paste into an email")
        }
    }
     ]]>
</script>

See the alert line which currently has static text? I want to replace that text string with the value of:

<xsl:value-of select="$Translations/msa:Translations/msa:*[local-name() = $LangCode]/msa:AlertText"/>


I only used the CDATA because I was fed up on Visual Studio reformatting my document and left aligning all the Javascript as a white block.

question from:https://stackoverflow.com/questions/65891644/how-can-i-embed-a-xslvalue-of-result-into-a-cdata-block

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have managed to do this by simply splitting my CDATA:

<script type="text/javascript">
    <![CDATA[
    function clearSelection() {
        if (document.getSelection) { // for all new browsers (IE9+, Chrome, Firefox)
            document.getSelection().removeAllRanges();
            document.getSelection().addRange(document.createRange());
            console.log("document.getSelection");
        } else if (window.getSelection) { // equals with the document.getSelection (MSDN info)
            if (window.getSelection().removeAllRanges) { // for all new browsers (IE9+, Chrome, Firefox)
                window.getSelection().removeAllRanges();
                window.getSelection().addRange(document.createRange());
                console.log("window.getSelection.removeAllRanges");
            } else if (window.getSelection().empty) { // Chrome supports this as well
                window.getSelection().empty();
                console.log("window.getSelection.empty");
            }
        } else if (document.selection) { // IE8-
            document.selection.empty();
            console.log("document.selection.empty");
        }
    }
    function CopyToClipboard(containerid) {
        clearSelection();
        if (document.selection) {
            var range = document.body.createTextRange();
            range.moveToElementText(document.getElementById(containerid));
            range.select().createTextRange();
            document.execCommand("copy");
        } else if (window.getSelection) {
            var range = document.createRange();
            range.selectNode(document.getElementById(containerid));
            window.getSelection().addRange(range);
            document.execCommand("copy");
            alert("]]><xsl:value-of select="$Translations/msa:Translations/msa:*[local-name() = $LangCode]/msa:AlertText"/><![CDATA[")
        }
    }
     ]]>
</script>

Please letme know if there was an even simpler way.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...