簡體   English   中英

如何將 xsl:value-of 結果嵌入到 CDATA 塊中?

[英]How can I embed a xsl:value-of result into a CDATA block?

我的 XSL 文件中有這個片段:

<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>

看到當前有 static 文本的alert行了嗎? 我想將該文本字符串替換為以下值:

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


我只使用了CDATA ,因為我厭倦了 Visual Studio 重新格式化我的文檔並將所有 Javascript 左對齊為一個白色塊。

我已經設法通過簡單地拆分我的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>

請讓我知道是否有更簡單的方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM