XML to XML using XSLT through C# -


i've got xml file (book) need make changes before creating output xml file.

i've got xslt transform file part of job fine, i'm needing go 1 step further i'm struggling.

in c# i'm using xslcompiledtransform object trigger transform task , not works because xml file output empty ...

code behind

xslcompiledtransform transform = new xslcompiledtransform(); transform.load(server.mappath("~/rss91.xslt")); transform.transform(server.mappath("~/book.xml"), server.mappath("~/output.xml")); 

rss91.xslt

<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">   <xsl:output method="html" indent="yes"/>   <xsl:param name="title"/>   <xsl:template match="rss">     <xsl:for-each select="channel/item">       <br>         <strong>           <a href="{link}" target="_main">             <xsl:value-of select="title"/>           </a>         </strong>         <br></br>         <xsl:value-of select="description" disable-output-escaping="yes"/>       </br>       <br></br>       <xsl:value-of select="pubdate"/>       <br></br>     </xsl:for-each>   </xsl:template>   <xsl:template match="description">     <br>       <xsl:value-of select="."/>     </br>   </xsl:template> </xsl:stylesheet> 

book.xml

<?xml version="1.0" encoding="utf-8" ?> <rss>   <title></title> </rss> 

as suggested @henkholtermann, empty output xml document expected, given input xml , xslt stylesheet apply.

your xslt stylesheets works fine - transform input xml has nothing it. let me explain why.

in stylesheet, there 2 templates match for

  • rss elements
  • description elements

when transform input xml:

<?xml version="1.0" encoding="utf-8" ?> <rss>   <title></title> </rss> 

the first template triggered, because there rss element in input. first instruction inside template is

<xsl:for-each select="channel/item"> 

which nothing since there neither channel nor item element inside in input xml. thus, first template triggered, not output whole.

the second template not triggered @ all, there no description element in input xml.

to summarize, usually, xslt stylesheet tailored type of input xml documents. relies either on structure being present in input xml or on values or other content being present. exception identity transform can applied kind of well-formed xml.


i'm sorry have not figured out need do

well, have 2 pieces of advice.

  • this accurately describes doing:

    imagine own cow. if oversimplify process, cows transform grass milk. that's simple - input grass , cows output milk. reason why works cow's digestive system "knows" how turn grass milk. prepared masticate grass. now, feeding cow stones , old tires. why expect happily produce milk?

  • learn xslt yourself. read book, study examples, work through tutorial.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -