如何将 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>
看到当前有静态文本的 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>
请告诉我是否有更简单的方法。
我的 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>
看到当前有静态文本的 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>
请告诉我是否有更简单的方法。