Question

My XML does have some styling within it. The output of the XslCompiledTransform Transform results in HTML which does not have these style tags. Is there some way to tell the XslCompiledTransform to keep them? or should the XslCompiledTransform keep them by default?

here's my xml

> <codeSnippetFull>
>         <span class="kwrd">event</span> 
>         OnCreate {
>         <span class="kwrd">if</span>
>              (Count == 0)
>                   AddE(D); <span class="rem">//  comment </span>
>         }
>        </codeSnippetFull>

my xslt just pulls out the whole element

         <xsl:value-of select="THelpDocument/HelpBody/example/codeSnippetFull"/>

here's my C#, I've nothing other than the defaults applied:

 // Load the style sheet. 
 XslCompiledTransform xslt = new XslCompiledTransform();
 xslt.Load(args[0]);

......
         xslt.Transform(xmlFileName, Path.Combine(htmlOutputPath, Path.GetFileNameWithoutExtension(xmlFileName) + ".html"));

The reason I'm not doing the styling from the xslt is because block could have and amount of styles applied, mixed in with random text. It's styling certain words in paragraphs.

Was it helpful?

Solution

Your XSLT code

<xsl:value-of select="THelpDocument/HelpBody/example/codeSnippetFull"/>

doesn't actually copy the (markup) contents of the <codeSnippetFull> element. <xsl:value-of> is used to create text nodes. Value-of converts the selected node to a string. String value of an element is the concatenation of the text nodes that are descendants of the selected element. String value of a node set (for example: multiple elements selected) is the string value of the first node in the set.

To copy elements in XSLT you could use

  1. <xs:copy> that copies the selected node but not its attributes or children
  2. <xs:copy-of> that copies the whole selected XML fragment (=also all descendants and attributes)
  3. an identity template i.e. a recursive template with <xs:copy>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top