How can you deal with embedded XML tags in XSLT?












13















I am using XSLT to convert XML to HTML. I am having trouble figuring out how to deal with embedded XML nodes for formatting. For example, let's say I have the XML element:



<favoriteMovie>the <i>Star Wars</i> saga</favoriteMovie>



However, during XLST, the <i> tag gets ignored, so "Star Wars" is not italicized in the HTML output. Is there a relatively simple way to fix this?



test.xml:



<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.html.xsl"?>
<favoriteMovies>
<favoriteMovie>the <i>Star Wars</i> saga</favoriteMovie>
</favoriteMovies>


test.html.xsl:



<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:template match="/">
<html>
<head />
<body>
<ul>
<xsl:for-each select="favoriteMovies/favoriteMovie">
<li><xsl:value-of select="." /></li>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>
</xsl:stylesheet>









share|improve this question

























  • @Craig, show us the XSLT (the relevant bits).

    – mzjn
    Jan 16 '11 at 19:45






  • 1





    Good question, +1. See my answer for explanation of the cause of the problem and two complete and short solutions. Do note that the currently accepted answer is completely wrong. Putting markup into a CDATA section converts this into unusable, 1-dimentional text and is generally identified as a bad practice.

    – Dimitre Novatchev
    Jan 16 '11 at 21:27











  • @Dimitre Novatchev, unless there's absolutely no NEED to treat that html as structured, and its only purpose is to be passed to the browser as-is with no risk of breaking the original XML structure with arbitraty html tags.

    – Dennis Kreminsky
    Jan 16 '11 at 21:50











  • Let's get to understanding before placing judgments on each other. Please, elaborate on the "destroyed markup", I'm not following you.

    – Dennis Kreminsky
    Jan 16 '11 at 22:36











  • @etranger: You can very easily find why destroying markup is bad practice -- just search. You may start with this: xml.silmaril.ie/cdata.html , but there are numerous other sources which you can easily find.

    – Dimitre Novatchev
    Jan 16 '11 at 22:49
















13















I am using XSLT to convert XML to HTML. I am having trouble figuring out how to deal with embedded XML nodes for formatting. For example, let's say I have the XML element:



<favoriteMovie>the <i>Star Wars</i> saga</favoriteMovie>



However, during XLST, the <i> tag gets ignored, so "Star Wars" is not italicized in the HTML output. Is there a relatively simple way to fix this?



test.xml:



<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.html.xsl"?>
<favoriteMovies>
<favoriteMovie>the <i>Star Wars</i> saga</favoriteMovie>
</favoriteMovies>


test.html.xsl:



<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:template match="/">
<html>
<head />
<body>
<ul>
<xsl:for-each select="favoriteMovies/favoriteMovie">
<li><xsl:value-of select="." /></li>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>
</xsl:stylesheet>









share|improve this question

























  • @Craig, show us the XSLT (the relevant bits).

    – mzjn
    Jan 16 '11 at 19:45






  • 1





    Good question, +1. See my answer for explanation of the cause of the problem and two complete and short solutions. Do note that the currently accepted answer is completely wrong. Putting markup into a CDATA section converts this into unusable, 1-dimentional text and is generally identified as a bad practice.

    – Dimitre Novatchev
    Jan 16 '11 at 21:27











  • @Dimitre Novatchev, unless there's absolutely no NEED to treat that html as structured, and its only purpose is to be passed to the browser as-is with no risk of breaking the original XML structure with arbitraty html tags.

    – Dennis Kreminsky
    Jan 16 '11 at 21:50











  • Let's get to understanding before placing judgments on each other. Please, elaborate on the "destroyed markup", I'm not following you.

    – Dennis Kreminsky
    Jan 16 '11 at 22:36











  • @etranger: You can very easily find why destroying markup is bad practice -- just search. You may start with this: xml.silmaril.ie/cdata.html , but there are numerous other sources which you can easily find.

    – Dimitre Novatchev
    Jan 16 '11 at 22:49














13












13








13


3






I am using XSLT to convert XML to HTML. I am having trouble figuring out how to deal with embedded XML nodes for formatting. For example, let's say I have the XML element:



<favoriteMovie>the <i>Star Wars</i> saga</favoriteMovie>



However, during XLST, the <i> tag gets ignored, so "Star Wars" is not italicized in the HTML output. Is there a relatively simple way to fix this?



test.xml:



<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.html.xsl"?>
<favoriteMovies>
<favoriteMovie>the <i>Star Wars</i> saga</favoriteMovie>
</favoriteMovies>


test.html.xsl:



<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:template match="/">
<html>
<head />
<body>
<ul>
<xsl:for-each select="favoriteMovies/favoriteMovie">
<li><xsl:value-of select="." /></li>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>
</xsl:stylesheet>









share|improve this question
















I am using XSLT to convert XML to HTML. I am having trouble figuring out how to deal with embedded XML nodes for formatting. For example, let's say I have the XML element:



<favoriteMovie>the <i>Star Wars</i> saga</favoriteMovie>



However, during XLST, the <i> tag gets ignored, so "Star Wars" is not italicized in the HTML output. Is there a relatively simple way to fix this?



test.xml:



<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.html.xsl"?>
<favoriteMovies>
<favoriteMovie>the <i>Star Wars</i> saga</favoriteMovie>
</favoriteMovies>


test.html.xsl:



<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:template match="/">
<html>
<head />
<body>
<ul>
<xsl:for-each select="favoriteMovies/favoriteMovie">
<li><xsl:value-of select="." /></li>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>
</xsl:stylesheet>






html xml xslt formatting






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 16 '11 at 20:29







Craig W

















asked Jan 16 '11 at 19:33









Craig WCraig W

1,64032241




1,64032241













  • @Craig, show us the XSLT (the relevant bits).

    – mzjn
    Jan 16 '11 at 19:45






  • 1





    Good question, +1. See my answer for explanation of the cause of the problem and two complete and short solutions. Do note that the currently accepted answer is completely wrong. Putting markup into a CDATA section converts this into unusable, 1-dimentional text and is generally identified as a bad practice.

    – Dimitre Novatchev
    Jan 16 '11 at 21:27











  • @Dimitre Novatchev, unless there's absolutely no NEED to treat that html as structured, and its only purpose is to be passed to the browser as-is with no risk of breaking the original XML structure with arbitraty html tags.

    – Dennis Kreminsky
    Jan 16 '11 at 21:50











  • Let's get to understanding before placing judgments on each other. Please, elaborate on the "destroyed markup", I'm not following you.

    – Dennis Kreminsky
    Jan 16 '11 at 22:36











  • @etranger: You can very easily find why destroying markup is bad practice -- just search. You may start with this: xml.silmaril.ie/cdata.html , but there are numerous other sources which you can easily find.

    – Dimitre Novatchev
    Jan 16 '11 at 22:49



















  • @Craig, show us the XSLT (the relevant bits).

    – mzjn
    Jan 16 '11 at 19:45






  • 1





    Good question, +1. See my answer for explanation of the cause of the problem and two complete and short solutions. Do note that the currently accepted answer is completely wrong. Putting markup into a CDATA section converts this into unusable, 1-dimentional text and is generally identified as a bad practice.

    – Dimitre Novatchev
    Jan 16 '11 at 21:27











  • @Dimitre Novatchev, unless there's absolutely no NEED to treat that html as structured, and its only purpose is to be passed to the browser as-is with no risk of breaking the original XML structure with arbitraty html tags.

    – Dennis Kreminsky
    Jan 16 '11 at 21:50











  • Let's get to understanding before placing judgments on each other. Please, elaborate on the "destroyed markup", I'm not following you.

    – Dennis Kreminsky
    Jan 16 '11 at 22:36











  • @etranger: You can very easily find why destroying markup is bad practice -- just search. You may start with this: xml.silmaril.ie/cdata.html , but there are numerous other sources which you can easily find.

    – Dimitre Novatchev
    Jan 16 '11 at 22:49

















@Craig, show us the XSLT (the relevant bits).

– mzjn
Jan 16 '11 at 19:45





@Craig, show us the XSLT (the relevant bits).

– mzjn
Jan 16 '11 at 19:45




1




1





Good question, +1. See my answer for explanation of the cause of the problem and two complete and short solutions. Do note that the currently accepted answer is completely wrong. Putting markup into a CDATA section converts this into unusable, 1-dimentional text and is generally identified as a bad practice.

– Dimitre Novatchev
Jan 16 '11 at 21:27





Good question, +1. See my answer for explanation of the cause of the problem and two complete and short solutions. Do note that the currently accepted answer is completely wrong. Putting markup into a CDATA section converts this into unusable, 1-dimentional text and is generally identified as a bad practice.

– Dimitre Novatchev
Jan 16 '11 at 21:27













@Dimitre Novatchev, unless there's absolutely no NEED to treat that html as structured, and its only purpose is to be passed to the browser as-is with no risk of breaking the original XML structure with arbitraty html tags.

– Dennis Kreminsky
Jan 16 '11 at 21:50





@Dimitre Novatchev, unless there's absolutely no NEED to treat that html as structured, and its only purpose is to be passed to the browser as-is with no risk of breaking the original XML structure with arbitraty html tags.

– Dennis Kreminsky
Jan 16 '11 at 21:50













Let's get to understanding before placing judgments on each other. Please, elaborate on the "destroyed markup", I'm not following you.

– Dennis Kreminsky
Jan 16 '11 at 22:36





Let's get to understanding before placing judgments on each other. Please, elaborate on the "destroyed markup", I'm not following you.

– Dennis Kreminsky
Jan 16 '11 at 22:36













@etranger: You can very easily find why destroying markup is bad practice -- just search. You may start with this: xml.silmaril.ie/cdata.html , but there are numerous other sources which you can easily find.

– Dimitre Novatchev
Jan 16 '11 at 22:49





@etranger: You can very easily find why destroying markup is bad practice -- just search. You may start with this: xml.silmaril.ie/cdata.html , but there are numerous other sources which you can easily find.

– Dimitre Novatchev
Jan 16 '11 at 22:49












4 Answers
4






active

oldest

votes


















11















However, during XLST, the <i> tag gets
ignored, so "Star Wars" is not
italicized in the HTML output. Is
there a relatively simple way to fix
this?




Your problem is here:




<ul>
<xsl:for-each select="favoriteMovies/favoriteMovie">
<li><xsl:value-of select="."/></li>
</xsl:for-each>
</ul>



The <xsl:value-of> instruction is used to create a text node. In doing so it copies to the output the string value of the XPath expression specified in the select attribute of this XSLT instruction. The string value of an element is the concatenation of all its text-node descendents.



So this is how you get the reported output.



Solution:



Use the <xsl:copy-of> instruction, which copies all the nodes that are specified in its select attribute:



<ul>
<xsl:for-each select="favoriteMovies/favoriteMovie">
<li><xsl:copy-of select="node()"/></li>
</xsl:for-each>
</ul>


Another solution, more alligned with the principles of XSLT avoids using <xsl:for-each> at all:



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

<xsl:template match="/">
<html>
<head />
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

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

<xsl:template match="favoriteMovie">
<li><xsl:copy-of select="node()"/></li>
</xsl:template>
</xsl:stylesheet>


When any of the two solutions defined above are applied to the provided XML document:



<favoriteMovies>
<favoriteMovie>the
<i>Star Wars</i> saga
</favoriteMovie>
</favoriteMovies>


the wanted, correct result is produced:



<html>
<head/>
<body>
<ul>
<li>the
<i>Star Wars</i> saga
</li>
</ul>
</body>
</html>





share|improve this answer


























  • I prefer this answer because it is simpler and works without breaking my plain text XSLT. Thanks!

    – Craig W
    Jan 16 '11 at 21:33











  • @James-Walford: There is one issue with your answer: You cannot know in advance what html elements would be in a favoriteMovie, therefore supplying separate templates matching any possible html element is unrealistic. If you really want to avoid using xsl:copy-of you need to use the identity rule. I didn't provide a solution with the identity rule, because this goes too-far from the original question.

    – Dimitre Novatchev
    Jan 16 '11 at 21:43











  • I should be able to figure this out, but if I want to do the same thing and I always have a single node instead of multiple, what would the XSL syntax look like? I tried changing <xsl:value-of select="title" /> to <xsl:copy-of select="title" />, but then the <title> tag shows up in the raw HTML and it doesn't render correctly.

    – Craig W
    Jan 16 '11 at 21:57











  • @Dimitre Novatchev thanks - good point, my answer was based on it being only i elements.

    – James Walford
    Jan 16 '11 at 22:09











  • Got it: <xsl:copy-of select="title/node()" />

    – Craig W
    Jan 16 '11 at 22:23



















2














You should use xsl:copy to copy the i node .



http://msdn.microsoft.com/en-us/library/ms256128.aspx



    <?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:template match="/">
<html>
<head />
<body>
<xsl:apply-templates></xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="favoriteMovies">
<ul>
<xsl:apply-templates></xsl:apply-templates>
</ul>
</xsl:template>
<xsl:template match="favoriteMovie">
<li>
<xsl:apply-templates></xsl:apply-templates>
</li>
</xsl:template>
<xsl:template match="i">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>





share|improve this answer


























  • This would be a wrong way to do it generally, because <i> doesn't come from the source XML namespace, but HTML namespace and should be treated that way, or not as a tag at all and hence as part of CDATA.

    – Dennis Kreminsky
    Jan 16 '11 at 20:13






  • 1





    There's no indication that there are any namespace references in his XML, and he's attempting to output html anyway. His input doesn't include CDATA, so there seems little point in telling him how he should process it if it did.

    – James Walford
    Jan 16 '11 at 20:20











  • The point is, his code can contain any html tags, including malformed text etc, it shouldn't be treated the same way you treat source xml. please get my idea that it's not about formal namespaces, but rather the logical scope of use of <favoriteMovies> as structure and <i> as markup

    – Dennis Kreminsky
    Jan 16 '11 at 20:33






  • 3





    As far as I can see your comment is more relevant to the construction of the original XML. If it contains unclosed HTML elements that aren't in CDATA then it won't be well formed anyway. If his XML is well formed but just happens to contain some HTML elements, with no explicit namespacing, then merely copying them out isn't a problem.

    – James Walford
    Jan 16 '11 at 20:53



















2














You should use 'disable-output-escaping' attribute. The general format of element is:



<xsl:value-of select="expression" disable-output-escaping="yes|no" />


'disable-output-escaping' is optional. "yes" indicates that special characters (like "<") should be output as is. "no" indicates that special characters (like "<") should be output as "<". Default is "no".



Therefore just change your code to:



<xsl:template match="favoriteMovie">
<xsl:copy-of select="node()" disable-output-escaping="yes"/>
</xsl:template>





share|improve this answer
























  • Why do I get 'disable-output-escaping' is an invalid attribute for the 'xsl:copy-of' element. ?

    – FMFF
    Apr 26 '13 at 21:13











  • disable-output-escaping is not universally supported and its use is discouraged. See stackoverflow.com/a/701793/130121

    – chiborg
    Jan 6 '14 at 13:34



















-7














Two things to note.



First. Make sure tags are screened in CDATA



<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.html.xsl"?>
<favoriteMovies>
<favoriteMovie><![CDATA[the <i>Star Wars</i> saga]]></favoriteMovie>
</favoriteMovies>


Second. Disable output escaping:



<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:template match="/">
<html>
<head />
<body>
<ul>
<xsl:for-each select="favoriteMovies/favoriteMovie">
<li><xsl:value-of select="." disable-output-escaping="yes" /></li>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>


EDIT: managed it with the editor, now the code is shown as it should



EDIT2: included changes in your code



EDIT3: To whom it may concern, the very domain of the problem in question is about structuring movies information, and not html data. HTML is there for markup purposes only, imagine having, say, html title tag inside favoriteMovie, whereas the same named tag title could be a valid tag in the movies database. These title's CLEARLY have to be interpreted differently. This justifies using CDATA and then disabling output when processing.






share|improve this answer


























  • Answer editor breaks my text, hope it looks good for you.

    – Dennis Kreminsky
    Jan 16 '11 at 19:42











  • 1. Doesn't work as expected; the HTML ends up looking like: the &lt;i&gt;Star Wars&lt;/i&gt; saga

    – Craig W
    Jan 16 '11 at 20:06













  • Using gt and lt entities was my attempt to counteract editor problems, don't use them in your document. The point is to use CDATA to wrap HTML tags inside XML tags.

    – Dennis Kreminsky
    Jan 16 '11 at 20:07













  • 2. Doesn't seem to change anything, the <i> tag is still ignored

    – Craig W
    Jan 16 '11 at 20:07






  • 1





    Re: EDIT 3 - you seem to be attempting to answer a question he hasn't asked.

    – James Walford
    Jan 16 '11 at 21:47











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4707571%2fhow-can-you-deal-with-embedded-xml-tags-in-xslt%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























4 Answers
4






active

oldest

votes








4 Answers
4






active

oldest

votes









active

oldest

votes






active

oldest

votes









11















However, during XLST, the <i> tag gets
ignored, so "Star Wars" is not
italicized in the HTML output. Is
there a relatively simple way to fix
this?




Your problem is here:




<ul>
<xsl:for-each select="favoriteMovies/favoriteMovie">
<li><xsl:value-of select="."/></li>
</xsl:for-each>
</ul>



The <xsl:value-of> instruction is used to create a text node. In doing so it copies to the output the string value of the XPath expression specified in the select attribute of this XSLT instruction. The string value of an element is the concatenation of all its text-node descendents.



So this is how you get the reported output.



Solution:



Use the <xsl:copy-of> instruction, which copies all the nodes that are specified in its select attribute:



<ul>
<xsl:for-each select="favoriteMovies/favoriteMovie">
<li><xsl:copy-of select="node()"/></li>
</xsl:for-each>
</ul>


Another solution, more alligned with the principles of XSLT avoids using <xsl:for-each> at all:



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

<xsl:template match="/">
<html>
<head />
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

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

<xsl:template match="favoriteMovie">
<li><xsl:copy-of select="node()"/></li>
</xsl:template>
</xsl:stylesheet>


When any of the two solutions defined above are applied to the provided XML document:



<favoriteMovies>
<favoriteMovie>the
<i>Star Wars</i> saga
</favoriteMovie>
</favoriteMovies>


the wanted, correct result is produced:



<html>
<head/>
<body>
<ul>
<li>the
<i>Star Wars</i> saga
</li>
</ul>
</body>
</html>





share|improve this answer


























  • I prefer this answer because it is simpler and works without breaking my plain text XSLT. Thanks!

    – Craig W
    Jan 16 '11 at 21:33











  • @James-Walford: There is one issue with your answer: You cannot know in advance what html elements would be in a favoriteMovie, therefore supplying separate templates matching any possible html element is unrealistic. If you really want to avoid using xsl:copy-of you need to use the identity rule. I didn't provide a solution with the identity rule, because this goes too-far from the original question.

    – Dimitre Novatchev
    Jan 16 '11 at 21:43











  • I should be able to figure this out, but if I want to do the same thing and I always have a single node instead of multiple, what would the XSL syntax look like? I tried changing <xsl:value-of select="title" /> to <xsl:copy-of select="title" />, but then the <title> tag shows up in the raw HTML and it doesn't render correctly.

    – Craig W
    Jan 16 '11 at 21:57











  • @Dimitre Novatchev thanks - good point, my answer was based on it being only i elements.

    – James Walford
    Jan 16 '11 at 22:09











  • Got it: <xsl:copy-of select="title/node()" />

    – Craig W
    Jan 16 '11 at 22:23
















11















However, during XLST, the <i> tag gets
ignored, so "Star Wars" is not
italicized in the HTML output. Is
there a relatively simple way to fix
this?




Your problem is here:




<ul>
<xsl:for-each select="favoriteMovies/favoriteMovie">
<li><xsl:value-of select="."/></li>
</xsl:for-each>
</ul>



The <xsl:value-of> instruction is used to create a text node. In doing so it copies to the output the string value of the XPath expression specified in the select attribute of this XSLT instruction. The string value of an element is the concatenation of all its text-node descendents.



So this is how you get the reported output.



Solution:



Use the <xsl:copy-of> instruction, which copies all the nodes that are specified in its select attribute:



<ul>
<xsl:for-each select="favoriteMovies/favoriteMovie">
<li><xsl:copy-of select="node()"/></li>
</xsl:for-each>
</ul>


Another solution, more alligned with the principles of XSLT avoids using <xsl:for-each> at all:



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

<xsl:template match="/">
<html>
<head />
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

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

<xsl:template match="favoriteMovie">
<li><xsl:copy-of select="node()"/></li>
</xsl:template>
</xsl:stylesheet>


When any of the two solutions defined above are applied to the provided XML document:



<favoriteMovies>
<favoriteMovie>the
<i>Star Wars</i> saga
</favoriteMovie>
</favoriteMovies>


the wanted, correct result is produced:



<html>
<head/>
<body>
<ul>
<li>the
<i>Star Wars</i> saga
</li>
</ul>
</body>
</html>





share|improve this answer


























  • I prefer this answer because it is simpler and works without breaking my plain text XSLT. Thanks!

    – Craig W
    Jan 16 '11 at 21:33











  • @James-Walford: There is one issue with your answer: You cannot know in advance what html elements would be in a favoriteMovie, therefore supplying separate templates matching any possible html element is unrealistic. If you really want to avoid using xsl:copy-of you need to use the identity rule. I didn't provide a solution with the identity rule, because this goes too-far from the original question.

    – Dimitre Novatchev
    Jan 16 '11 at 21:43











  • I should be able to figure this out, but if I want to do the same thing and I always have a single node instead of multiple, what would the XSL syntax look like? I tried changing <xsl:value-of select="title" /> to <xsl:copy-of select="title" />, but then the <title> tag shows up in the raw HTML and it doesn't render correctly.

    – Craig W
    Jan 16 '11 at 21:57











  • @Dimitre Novatchev thanks - good point, my answer was based on it being only i elements.

    – James Walford
    Jan 16 '11 at 22:09











  • Got it: <xsl:copy-of select="title/node()" />

    – Craig W
    Jan 16 '11 at 22:23














11












11








11








However, during XLST, the <i> tag gets
ignored, so "Star Wars" is not
italicized in the HTML output. Is
there a relatively simple way to fix
this?




Your problem is here:




<ul>
<xsl:for-each select="favoriteMovies/favoriteMovie">
<li><xsl:value-of select="."/></li>
</xsl:for-each>
</ul>



The <xsl:value-of> instruction is used to create a text node. In doing so it copies to the output the string value of the XPath expression specified in the select attribute of this XSLT instruction. The string value of an element is the concatenation of all its text-node descendents.



So this is how you get the reported output.



Solution:



Use the <xsl:copy-of> instruction, which copies all the nodes that are specified in its select attribute:



<ul>
<xsl:for-each select="favoriteMovies/favoriteMovie">
<li><xsl:copy-of select="node()"/></li>
</xsl:for-each>
</ul>


Another solution, more alligned with the principles of XSLT avoids using <xsl:for-each> at all:



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

<xsl:template match="/">
<html>
<head />
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

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

<xsl:template match="favoriteMovie">
<li><xsl:copy-of select="node()"/></li>
</xsl:template>
</xsl:stylesheet>


When any of the two solutions defined above are applied to the provided XML document:



<favoriteMovies>
<favoriteMovie>the
<i>Star Wars</i> saga
</favoriteMovie>
</favoriteMovies>


the wanted, correct result is produced:



<html>
<head/>
<body>
<ul>
<li>the
<i>Star Wars</i> saga
</li>
</ul>
</body>
</html>





share|improve this answer
















However, during XLST, the <i> tag gets
ignored, so "Star Wars" is not
italicized in the HTML output. Is
there a relatively simple way to fix
this?




Your problem is here:




<ul>
<xsl:for-each select="favoriteMovies/favoriteMovie">
<li><xsl:value-of select="."/></li>
</xsl:for-each>
</ul>



The <xsl:value-of> instruction is used to create a text node. In doing so it copies to the output the string value of the XPath expression specified in the select attribute of this XSLT instruction. The string value of an element is the concatenation of all its text-node descendents.



So this is how you get the reported output.



Solution:



Use the <xsl:copy-of> instruction, which copies all the nodes that are specified in its select attribute:



<ul>
<xsl:for-each select="favoriteMovies/favoriteMovie">
<li><xsl:copy-of select="node()"/></li>
</xsl:for-each>
</ul>


Another solution, more alligned with the principles of XSLT avoids using <xsl:for-each> at all:



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

<xsl:template match="/">
<html>
<head />
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

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

<xsl:template match="favoriteMovie">
<li><xsl:copy-of select="node()"/></li>
</xsl:template>
</xsl:stylesheet>


When any of the two solutions defined above are applied to the provided XML document:



<favoriteMovies>
<favoriteMovie>the
<i>Star Wars</i> saga
</favoriteMovie>
</favoriteMovies>


the wanted, correct result is produced:



<html>
<head/>
<body>
<ul>
<li>the
<i>Star Wars</i> saga
</li>
</ul>
</body>
</html>






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 16 '11 at 21:40

























answered Jan 16 '11 at 21:24









Dimitre NovatchevDimitre Novatchev

211k22244372




211k22244372













  • I prefer this answer because it is simpler and works without breaking my plain text XSLT. Thanks!

    – Craig W
    Jan 16 '11 at 21:33











  • @James-Walford: There is one issue with your answer: You cannot know in advance what html elements would be in a favoriteMovie, therefore supplying separate templates matching any possible html element is unrealistic. If you really want to avoid using xsl:copy-of you need to use the identity rule. I didn't provide a solution with the identity rule, because this goes too-far from the original question.

    – Dimitre Novatchev
    Jan 16 '11 at 21:43











  • I should be able to figure this out, but if I want to do the same thing and I always have a single node instead of multiple, what would the XSL syntax look like? I tried changing <xsl:value-of select="title" /> to <xsl:copy-of select="title" />, but then the <title> tag shows up in the raw HTML and it doesn't render correctly.

    – Craig W
    Jan 16 '11 at 21:57











  • @Dimitre Novatchev thanks - good point, my answer was based on it being only i elements.

    – James Walford
    Jan 16 '11 at 22:09











  • Got it: <xsl:copy-of select="title/node()" />

    – Craig W
    Jan 16 '11 at 22:23



















  • I prefer this answer because it is simpler and works without breaking my plain text XSLT. Thanks!

    – Craig W
    Jan 16 '11 at 21:33











  • @James-Walford: There is one issue with your answer: You cannot know in advance what html elements would be in a favoriteMovie, therefore supplying separate templates matching any possible html element is unrealistic. If you really want to avoid using xsl:copy-of you need to use the identity rule. I didn't provide a solution with the identity rule, because this goes too-far from the original question.

    – Dimitre Novatchev
    Jan 16 '11 at 21:43











  • I should be able to figure this out, but if I want to do the same thing and I always have a single node instead of multiple, what would the XSL syntax look like? I tried changing <xsl:value-of select="title" /> to <xsl:copy-of select="title" />, but then the <title> tag shows up in the raw HTML and it doesn't render correctly.

    – Craig W
    Jan 16 '11 at 21:57











  • @Dimitre Novatchev thanks - good point, my answer was based on it being only i elements.

    – James Walford
    Jan 16 '11 at 22:09











  • Got it: <xsl:copy-of select="title/node()" />

    – Craig W
    Jan 16 '11 at 22:23

















I prefer this answer because it is simpler and works without breaking my plain text XSLT. Thanks!

– Craig W
Jan 16 '11 at 21:33





I prefer this answer because it is simpler and works without breaking my plain text XSLT. Thanks!

– Craig W
Jan 16 '11 at 21:33













@James-Walford: There is one issue with your answer: You cannot know in advance what html elements would be in a favoriteMovie, therefore supplying separate templates matching any possible html element is unrealistic. If you really want to avoid using xsl:copy-of you need to use the identity rule. I didn't provide a solution with the identity rule, because this goes too-far from the original question.

– Dimitre Novatchev
Jan 16 '11 at 21:43





@James-Walford: There is one issue with your answer: You cannot know in advance what html elements would be in a favoriteMovie, therefore supplying separate templates matching any possible html element is unrealistic. If you really want to avoid using xsl:copy-of you need to use the identity rule. I didn't provide a solution with the identity rule, because this goes too-far from the original question.

– Dimitre Novatchev
Jan 16 '11 at 21:43













I should be able to figure this out, but if I want to do the same thing and I always have a single node instead of multiple, what would the XSL syntax look like? I tried changing <xsl:value-of select="title" /> to <xsl:copy-of select="title" />, but then the <title> tag shows up in the raw HTML and it doesn't render correctly.

– Craig W
Jan 16 '11 at 21:57





I should be able to figure this out, but if I want to do the same thing and I always have a single node instead of multiple, what would the XSL syntax look like? I tried changing <xsl:value-of select="title" /> to <xsl:copy-of select="title" />, but then the <title> tag shows up in the raw HTML and it doesn't render correctly.

– Craig W
Jan 16 '11 at 21:57













@Dimitre Novatchev thanks - good point, my answer was based on it being only i elements.

– James Walford
Jan 16 '11 at 22:09





@Dimitre Novatchev thanks - good point, my answer was based on it being only i elements.

– James Walford
Jan 16 '11 at 22:09













Got it: <xsl:copy-of select="title/node()" />

– Craig W
Jan 16 '11 at 22:23





Got it: <xsl:copy-of select="title/node()" />

– Craig W
Jan 16 '11 at 22:23













2














You should use xsl:copy to copy the i node .



http://msdn.microsoft.com/en-us/library/ms256128.aspx



    <?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:template match="/">
<html>
<head />
<body>
<xsl:apply-templates></xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="favoriteMovies">
<ul>
<xsl:apply-templates></xsl:apply-templates>
</ul>
</xsl:template>
<xsl:template match="favoriteMovie">
<li>
<xsl:apply-templates></xsl:apply-templates>
</li>
</xsl:template>
<xsl:template match="i">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>





share|improve this answer


























  • This would be a wrong way to do it generally, because <i> doesn't come from the source XML namespace, but HTML namespace and should be treated that way, or not as a tag at all and hence as part of CDATA.

    – Dennis Kreminsky
    Jan 16 '11 at 20:13






  • 1





    There's no indication that there are any namespace references in his XML, and he's attempting to output html anyway. His input doesn't include CDATA, so there seems little point in telling him how he should process it if it did.

    – James Walford
    Jan 16 '11 at 20:20











  • The point is, his code can contain any html tags, including malformed text etc, it shouldn't be treated the same way you treat source xml. please get my idea that it's not about formal namespaces, but rather the logical scope of use of <favoriteMovies> as structure and <i> as markup

    – Dennis Kreminsky
    Jan 16 '11 at 20:33






  • 3





    As far as I can see your comment is more relevant to the construction of the original XML. If it contains unclosed HTML elements that aren't in CDATA then it won't be well formed anyway. If his XML is well formed but just happens to contain some HTML elements, with no explicit namespacing, then merely copying them out isn't a problem.

    – James Walford
    Jan 16 '11 at 20:53
















2














You should use xsl:copy to copy the i node .



http://msdn.microsoft.com/en-us/library/ms256128.aspx



    <?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:template match="/">
<html>
<head />
<body>
<xsl:apply-templates></xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="favoriteMovies">
<ul>
<xsl:apply-templates></xsl:apply-templates>
</ul>
</xsl:template>
<xsl:template match="favoriteMovie">
<li>
<xsl:apply-templates></xsl:apply-templates>
</li>
</xsl:template>
<xsl:template match="i">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>





share|improve this answer


























  • This would be a wrong way to do it generally, because <i> doesn't come from the source XML namespace, but HTML namespace and should be treated that way, or not as a tag at all and hence as part of CDATA.

    – Dennis Kreminsky
    Jan 16 '11 at 20:13






  • 1





    There's no indication that there are any namespace references in his XML, and he's attempting to output html anyway. His input doesn't include CDATA, so there seems little point in telling him how he should process it if it did.

    – James Walford
    Jan 16 '11 at 20:20











  • The point is, his code can contain any html tags, including malformed text etc, it shouldn't be treated the same way you treat source xml. please get my idea that it's not about formal namespaces, but rather the logical scope of use of <favoriteMovies> as structure and <i> as markup

    – Dennis Kreminsky
    Jan 16 '11 at 20:33






  • 3





    As far as I can see your comment is more relevant to the construction of the original XML. If it contains unclosed HTML elements that aren't in CDATA then it won't be well formed anyway. If his XML is well formed but just happens to contain some HTML elements, with no explicit namespacing, then merely copying them out isn't a problem.

    – James Walford
    Jan 16 '11 at 20:53














2












2








2







You should use xsl:copy to copy the i node .



http://msdn.microsoft.com/en-us/library/ms256128.aspx



    <?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:template match="/">
<html>
<head />
<body>
<xsl:apply-templates></xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="favoriteMovies">
<ul>
<xsl:apply-templates></xsl:apply-templates>
</ul>
</xsl:template>
<xsl:template match="favoriteMovie">
<li>
<xsl:apply-templates></xsl:apply-templates>
</li>
</xsl:template>
<xsl:template match="i">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>





share|improve this answer















You should use xsl:copy to copy the i node .



http://msdn.microsoft.com/en-us/library/ms256128.aspx



    <?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:template match="/">
<html>
<head />
<body>
<xsl:apply-templates></xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="favoriteMovies">
<ul>
<xsl:apply-templates></xsl:apply-templates>
</ul>
</xsl:template>
<xsl:template match="favoriteMovie">
<li>
<xsl:apply-templates></xsl:apply-templates>
</li>
</xsl:template>
<xsl:template match="i">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 16 '11 at 21:23

























answered Jan 16 '11 at 19:58









James WalfordJames Walford

2,20711934




2,20711934













  • This would be a wrong way to do it generally, because <i> doesn't come from the source XML namespace, but HTML namespace and should be treated that way, or not as a tag at all and hence as part of CDATA.

    – Dennis Kreminsky
    Jan 16 '11 at 20:13






  • 1





    There's no indication that there are any namespace references in his XML, and he's attempting to output html anyway. His input doesn't include CDATA, so there seems little point in telling him how he should process it if it did.

    – James Walford
    Jan 16 '11 at 20:20











  • The point is, his code can contain any html tags, including malformed text etc, it shouldn't be treated the same way you treat source xml. please get my idea that it's not about formal namespaces, but rather the logical scope of use of <favoriteMovies> as structure and <i> as markup

    – Dennis Kreminsky
    Jan 16 '11 at 20:33






  • 3





    As far as I can see your comment is more relevant to the construction of the original XML. If it contains unclosed HTML elements that aren't in CDATA then it won't be well formed anyway. If his XML is well formed but just happens to contain some HTML elements, with no explicit namespacing, then merely copying them out isn't a problem.

    – James Walford
    Jan 16 '11 at 20:53



















  • This would be a wrong way to do it generally, because <i> doesn't come from the source XML namespace, but HTML namespace and should be treated that way, or not as a tag at all and hence as part of CDATA.

    – Dennis Kreminsky
    Jan 16 '11 at 20:13






  • 1





    There's no indication that there are any namespace references in his XML, and he's attempting to output html anyway. His input doesn't include CDATA, so there seems little point in telling him how he should process it if it did.

    – James Walford
    Jan 16 '11 at 20:20











  • The point is, his code can contain any html tags, including malformed text etc, it shouldn't be treated the same way you treat source xml. please get my idea that it's not about formal namespaces, but rather the logical scope of use of <favoriteMovies> as structure and <i> as markup

    – Dennis Kreminsky
    Jan 16 '11 at 20:33






  • 3





    As far as I can see your comment is more relevant to the construction of the original XML. If it contains unclosed HTML elements that aren't in CDATA then it won't be well formed anyway. If his XML is well formed but just happens to contain some HTML elements, with no explicit namespacing, then merely copying them out isn't a problem.

    – James Walford
    Jan 16 '11 at 20:53

















This would be a wrong way to do it generally, because <i> doesn't come from the source XML namespace, but HTML namespace and should be treated that way, or not as a tag at all and hence as part of CDATA.

– Dennis Kreminsky
Jan 16 '11 at 20:13





This would be a wrong way to do it generally, because <i> doesn't come from the source XML namespace, but HTML namespace and should be treated that way, or not as a tag at all and hence as part of CDATA.

– Dennis Kreminsky
Jan 16 '11 at 20:13




1




1





There's no indication that there are any namespace references in his XML, and he's attempting to output html anyway. His input doesn't include CDATA, so there seems little point in telling him how he should process it if it did.

– James Walford
Jan 16 '11 at 20:20





There's no indication that there are any namespace references in his XML, and he's attempting to output html anyway. His input doesn't include CDATA, so there seems little point in telling him how he should process it if it did.

– James Walford
Jan 16 '11 at 20:20













The point is, his code can contain any html tags, including malformed text etc, it shouldn't be treated the same way you treat source xml. please get my idea that it's not about formal namespaces, but rather the logical scope of use of <favoriteMovies> as structure and <i> as markup

– Dennis Kreminsky
Jan 16 '11 at 20:33





The point is, his code can contain any html tags, including malformed text etc, it shouldn't be treated the same way you treat source xml. please get my idea that it's not about formal namespaces, but rather the logical scope of use of <favoriteMovies> as structure and <i> as markup

– Dennis Kreminsky
Jan 16 '11 at 20:33




3




3





As far as I can see your comment is more relevant to the construction of the original XML. If it contains unclosed HTML elements that aren't in CDATA then it won't be well formed anyway. If his XML is well formed but just happens to contain some HTML elements, with no explicit namespacing, then merely copying them out isn't a problem.

– James Walford
Jan 16 '11 at 20:53





As far as I can see your comment is more relevant to the construction of the original XML. If it contains unclosed HTML elements that aren't in CDATA then it won't be well formed anyway. If his XML is well formed but just happens to contain some HTML elements, with no explicit namespacing, then merely copying them out isn't a problem.

– James Walford
Jan 16 '11 at 20:53











2














You should use 'disable-output-escaping' attribute. The general format of element is:



<xsl:value-of select="expression" disable-output-escaping="yes|no" />


'disable-output-escaping' is optional. "yes" indicates that special characters (like "<") should be output as is. "no" indicates that special characters (like "<") should be output as "<". Default is "no".



Therefore just change your code to:



<xsl:template match="favoriteMovie">
<xsl:copy-of select="node()" disable-output-escaping="yes"/>
</xsl:template>





share|improve this answer
























  • Why do I get 'disable-output-escaping' is an invalid attribute for the 'xsl:copy-of' element. ?

    – FMFF
    Apr 26 '13 at 21:13











  • disable-output-escaping is not universally supported and its use is discouraged. See stackoverflow.com/a/701793/130121

    – chiborg
    Jan 6 '14 at 13:34
















2














You should use 'disable-output-escaping' attribute. The general format of element is:



<xsl:value-of select="expression" disable-output-escaping="yes|no" />


'disable-output-escaping' is optional. "yes" indicates that special characters (like "<") should be output as is. "no" indicates that special characters (like "<") should be output as "<". Default is "no".



Therefore just change your code to:



<xsl:template match="favoriteMovie">
<xsl:copy-of select="node()" disable-output-escaping="yes"/>
</xsl:template>





share|improve this answer
























  • Why do I get 'disable-output-escaping' is an invalid attribute for the 'xsl:copy-of' element. ?

    – FMFF
    Apr 26 '13 at 21:13











  • disable-output-escaping is not universally supported and its use is discouraged. See stackoverflow.com/a/701793/130121

    – chiborg
    Jan 6 '14 at 13:34














2












2








2







You should use 'disable-output-escaping' attribute. The general format of element is:



<xsl:value-of select="expression" disable-output-escaping="yes|no" />


'disable-output-escaping' is optional. "yes" indicates that special characters (like "<") should be output as is. "no" indicates that special characters (like "<") should be output as "<". Default is "no".



Therefore just change your code to:



<xsl:template match="favoriteMovie">
<xsl:copy-of select="node()" disable-output-escaping="yes"/>
</xsl:template>





share|improve this answer













You should use 'disable-output-escaping' attribute. The general format of element is:



<xsl:value-of select="expression" disable-output-escaping="yes|no" />


'disable-output-escaping' is optional. "yes" indicates that special characters (like "<") should be output as is. "no" indicates that special characters (like "<") should be output as "<". Default is "no".



Therefore just change your code to:



<xsl:template match="favoriteMovie">
<xsl:copy-of select="node()" disable-output-escaping="yes"/>
</xsl:template>






share|improve this answer












share|improve this answer



share|improve this answer










answered Jun 18 '12 at 6:35









Amir SamakarAmir Samakar

212




212













  • Why do I get 'disable-output-escaping' is an invalid attribute for the 'xsl:copy-of' element. ?

    – FMFF
    Apr 26 '13 at 21:13











  • disable-output-escaping is not universally supported and its use is discouraged. See stackoverflow.com/a/701793/130121

    – chiborg
    Jan 6 '14 at 13:34



















  • Why do I get 'disable-output-escaping' is an invalid attribute for the 'xsl:copy-of' element. ?

    – FMFF
    Apr 26 '13 at 21:13











  • disable-output-escaping is not universally supported and its use is discouraged. See stackoverflow.com/a/701793/130121

    – chiborg
    Jan 6 '14 at 13:34

















Why do I get 'disable-output-escaping' is an invalid attribute for the 'xsl:copy-of' element. ?

– FMFF
Apr 26 '13 at 21:13





Why do I get 'disable-output-escaping' is an invalid attribute for the 'xsl:copy-of' element. ?

– FMFF
Apr 26 '13 at 21:13













disable-output-escaping is not universally supported and its use is discouraged. See stackoverflow.com/a/701793/130121

– chiborg
Jan 6 '14 at 13:34





disable-output-escaping is not universally supported and its use is discouraged. See stackoverflow.com/a/701793/130121

– chiborg
Jan 6 '14 at 13:34











-7














Two things to note.



First. Make sure tags are screened in CDATA



<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.html.xsl"?>
<favoriteMovies>
<favoriteMovie><![CDATA[the <i>Star Wars</i> saga]]></favoriteMovie>
</favoriteMovies>


Second. Disable output escaping:



<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:template match="/">
<html>
<head />
<body>
<ul>
<xsl:for-each select="favoriteMovies/favoriteMovie">
<li><xsl:value-of select="." disable-output-escaping="yes" /></li>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>


EDIT: managed it with the editor, now the code is shown as it should



EDIT2: included changes in your code



EDIT3: To whom it may concern, the very domain of the problem in question is about structuring movies information, and not html data. HTML is there for markup purposes only, imagine having, say, html title tag inside favoriteMovie, whereas the same named tag title could be a valid tag in the movies database. These title's CLEARLY have to be interpreted differently. This justifies using CDATA and then disabling output when processing.






share|improve this answer


























  • Answer editor breaks my text, hope it looks good for you.

    – Dennis Kreminsky
    Jan 16 '11 at 19:42











  • 1. Doesn't work as expected; the HTML ends up looking like: the &lt;i&gt;Star Wars&lt;/i&gt; saga

    – Craig W
    Jan 16 '11 at 20:06













  • Using gt and lt entities was my attempt to counteract editor problems, don't use them in your document. The point is to use CDATA to wrap HTML tags inside XML tags.

    – Dennis Kreminsky
    Jan 16 '11 at 20:07













  • 2. Doesn't seem to change anything, the <i> tag is still ignored

    – Craig W
    Jan 16 '11 at 20:07






  • 1





    Re: EDIT 3 - you seem to be attempting to answer a question he hasn't asked.

    – James Walford
    Jan 16 '11 at 21:47
















-7














Two things to note.



First. Make sure tags are screened in CDATA



<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.html.xsl"?>
<favoriteMovies>
<favoriteMovie><![CDATA[the <i>Star Wars</i> saga]]></favoriteMovie>
</favoriteMovies>


Second. Disable output escaping:



<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:template match="/">
<html>
<head />
<body>
<ul>
<xsl:for-each select="favoriteMovies/favoriteMovie">
<li><xsl:value-of select="." disable-output-escaping="yes" /></li>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>


EDIT: managed it with the editor, now the code is shown as it should



EDIT2: included changes in your code



EDIT3: To whom it may concern, the very domain of the problem in question is about structuring movies information, and not html data. HTML is there for markup purposes only, imagine having, say, html title tag inside favoriteMovie, whereas the same named tag title could be a valid tag in the movies database. These title's CLEARLY have to be interpreted differently. This justifies using CDATA and then disabling output when processing.






share|improve this answer


























  • Answer editor breaks my text, hope it looks good for you.

    – Dennis Kreminsky
    Jan 16 '11 at 19:42











  • 1. Doesn't work as expected; the HTML ends up looking like: the &lt;i&gt;Star Wars&lt;/i&gt; saga

    – Craig W
    Jan 16 '11 at 20:06













  • Using gt and lt entities was my attempt to counteract editor problems, don't use them in your document. The point is to use CDATA to wrap HTML tags inside XML tags.

    – Dennis Kreminsky
    Jan 16 '11 at 20:07













  • 2. Doesn't seem to change anything, the <i> tag is still ignored

    – Craig W
    Jan 16 '11 at 20:07






  • 1





    Re: EDIT 3 - you seem to be attempting to answer a question he hasn't asked.

    – James Walford
    Jan 16 '11 at 21:47














-7












-7








-7







Two things to note.



First. Make sure tags are screened in CDATA



<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.html.xsl"?>
<favoriteMovies>
<favoriteMovie><![CDATA[the <i>Star Wars</i> saga]]></favoriteMovie>
</favoriteMovies>


Second. Disable output escaping:



<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:template match="/">
<html>
<head />
<body>
<ul>
<xsl:for-each select="favoriteMovies/favoriteMovie">
<li><xsl:value-of select="." disable-output-escaping="yes" /></li>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>


EDIT: managed it with the editor, now the code is shown as it should



EDIT2: included changes in your code



EDIT3: To whom it may concern, the very domain of the problem in question is about structuring movies information, and not html data. HTML is there for markup purposes only, imagine having, say, html title tag inside favoriteMovie, whereas the same named tag title could be a valid tag in the movies database. These title's CLEARLY have to be interpreted differently. This justifies using CDATA and then disabling output when processing.






share|improve this answer















Two things to note.



First. Make sure tags are screened in CDATA



<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.html.xsl"?>
<favoriteMovies>
<favoriteMovie><![CDATA[the <i>Star Wars</i> saga]]></favoriteMovie>
</favoriteMovies>


Second. Disable output escaping:



<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:template match="/">
<html>
<head />
<body>
<ul>
<xsl:for-each select="favoriteMovies/favoriteMovie">
<li><xsl:value-of select="." disable-output-escaping="yes" /></li>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>


EDIT: managed it with the editor, now the code is shown as it should



EDIT2: included changes in your code



EDIT3: To whom it may concern, the very domain of the problem in question is about structuring movies information, and not html data. HTML is there for markup purposes only, imagine having, say, html title tag inside favoriteMovie, whereas the same named tag title could be a valid tag in the movies database. These title's CLEARLY have to be interpreted differently. This justifies using CDATA and then disabling output when processing.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 16 '11 at 21:43

























answered Jan 16 '11 at 19:40









Dennis KreminskyDennis Kreminsky

1,6741023




1,6741023













  • Answer editor breaks my text, hope it looks good for you.

    – Dennis Kreminsky
    Jan 16 '11 at 19:42











  • 1. Doesn't work as expected; the HTML ends up looking like: the &lt;i&gt;Star Wars&lt;/i&gt; saga

    – Craig W
    Jan 16 '11 at 20:06













  • Using gt and lt entities was my attempt to counteract editor problems, don't use them in your document. The point is to use CDATA to wrap HTML tags inside XML tags.

    – Dennis Kreminsky
    Jan 16 '11 at 20:07













  • 2. Doesn't seem to change anything, the <i> tag is still ignored

    – Craig W
    Jan 16 '11 at 20:07






  • 1





    Re: EDIT 3 - you seem to be attempting to answer a question he hasn't asked.

    – James Walford
    Jan 16 '11 at 21:47



















  • Answer editor breaks my text, hope it looks good for you.

    – Dennis Kreminsky
    Jan 16 '11 at 19:42











  • 1. Doesn't work as expected; the HTML ends up looking like: the &lt;i&gt;Star Wars&lt;/i&gt; saga

    – Craig W
    Jan 16 '11 at 20:06













  • Using gt and lt entities was my attempt to counteract editor problems, don't use them in your document. The point is to use CDATA to wrap HTML tags inside XML tags.

    – Dennis Kreminsky
    Jan 16 '11 at 20:07













  • 2. Doesn't seem to change anything, the <i> tag is still ignored

    – Craig W
    Jan 16 '11 at 20:07






  • 1





    Re: EDIT 3 - you seem to be attempting to answer a question he hasn't asked.

    – James Walford
    Jan 16 '11 at 21:47

















Answer editor breaks my text, hope it looks good for you.

– Dennis Kreminsky
Jan 16 '11 at 19:42





Answer editor breaks my text, hope it looks good for you.

– Dennis Kreminsky
Jan 16 '11 at 19:42













1. Doesn't work as expected; the HTML ends up looking like: the &lt;i&gt;Star Wars&lt;/i&gt; saga

– Craig W
Jan 16 '11 at 20:06







1. Doesn't work as expected; the HTML ends up looking like: the &lt;i&gt;Star Wars&lt;/i&gt; saga

– Craig W
Jan 16 '11 at 20:06















Using gt and lt entities was my attempt to counteract editor problems, don't use them in your document. The point is to use CDATA to wrap HTML tags inside XML tags.

– Dennis Kreminsky
Jan 16 '11 at 20:07







Using gt and lt entities was my attempt to counteract editor problems, don't use them in your document. The point is to use CDATA to wrap HTML tags inside XML tags.

– Dennis Kreminsky
Jan 16 '11 at 20:07















2. Doesn't seem to change anything, the <i> tag is still ignored

– Craig W
Jan 16 '11 at 20:07





2. Doesn't seem to change anything, the <i> tag is still ignored

– Craig W
Jan 16 '11 at 20:07




1




1





Re: EDIT 3 - you seem to be attempting to answer a question he hasn't asked.

– James Walford
Jan 16 '11 at 21:47





Re: EDIT 3 - you seem to be attempting to answer a question he hasn't asked.

– James Walford
Jan 16 '11 at 21:47


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4707571%2fhow-can-you-deal-with-embedded-xml-tags-in-xslt%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

Npm cannot find a required file even through it is in the searched directory