Solved

building html into my xslt stylesheet

Posted on 2010-08-26
19
226 Views
Last Modified: 2012-05-10
I have the following simple stylesheet that i transform using vb.net to integrate and display some xml:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/">
   
    <table border="0">      
      <xsl:for-each select="Orders/Order">
        <tr>
          <td>
            <xsl:value-of select="CustomerName"/>
            <br/>
           
            <xsl:if test="DeliveryCompany != ''">
              <xsl:value-of select="DeliveryCompany"/>
              <br/>
            </xsl:if>

            <xsl:value-of select="DeliveryStreet1"/><br/>

            <xsl:if test="DeliveryStreet2 != ''">
              <xsl:value-of select="DeliveryStreet2"/>
              <br/>
            </xsl:if>

            <xsl:value-of select="DeliveryCity"/><br/>
            <xsl:value-of select="DeliveryPostalCode"/>
           
          </td>
        </tr>
      </xsl:for-each>

    </table>

  </xsl:template>

</xsl:stylesheet>


This works fine.

However if I try and add a <h1> tag etc I start getting errors.

What do I need to add to allow me to be able to input more html?
0
Comment
Question by:scm0sml
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
  • 3
19 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 33531455
check the following example for html embedded in xslt:(http://www.ibm.com/developerworks/xml/library/x-tiphtml.html)<?xml version="1.0"?>     version="1.0">Select Choices<script type="text/javascript" version="1.3">function checkDate() {   var today = new Date();   var deadlineDate = new Date('3/3/2002');   if (today > deadlineDate) {        alert('The deadline has passed.');        return false;   } else {        return true;   }   }</script><form action="processform.jsp" method="post" onsubmit="return checkDate()">We will send you information on the subjects in which you'reinterested. Please check all that apply.
      <input type="submit" value="Submit Choices"/></form>            checkbox                                    checked                        
0
 
LVL 8

Expert Comment

by:Bob Hoffman
ID: 33531489
Should work as long as it's well formed. What is the error your getting?
0
 

Author Comment

by:scm0sml
ID: 33531682
the error im getting is:
Token StartElement in state EndRootElement would result in an invalid XML document. Make sure that the ConformanceLevel setting is set to ConformanceLevel.Fragment or ConformanceLevel.Auto if you want to write an XML fragment.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 42

Expert Comment

by:sedgwick
ID: 33531723
can you paste the whole thing here?
0
 

Author Comment

by:scm0sml
ID: 33531733
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/">
    <html>

      <head>
        <title></title>
      </head>
    </html>
    <body>
    <h1>next</h1>
    <table border="0">      
      <xsl:for-each select="Orders/Order">
        <tr>
          <td>
            <xsl:value-of select="CustomerName"/>
            <br/>
           
            <xsl:if test="DeliveryCompany != ''">
              <xsl:value-of select="DeliveryCompany"/>
              <br/>
            </xsl:if>

            <xsl:value-of select="DeliveryStreet1"/><br/>

            <xsl:if test="DeliveryStreet2 != ''">
              <xsl:value-of select="DeliveryStreet2"/>
              <br/>
            </xsl:if>

            <xsl:value-of select="DeliveryCity"/><br/>
            <xsl:value-of select="DeliveryPostalCode"/>
           
          </td>
        </tr>
      </xsl:for-each>

    </table>
    </body>
  </xsl:template>

</xsl:stylesheet>


0
 
LVL 8

Expert Comment

by:Bob Hoffman
ID: 33531735
Do you get the error in your xslt designer or in the web page when your doing the transformation? Can you post the xslt that generate the error.
0
 

Author Comment

by:scm0sml
ID: 33531750
when i do the transform! just posted the xslt :)
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 33531772
try this:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/">
    <html>

      <head>
        <title></title>
      </head>
 
    <body>
    <h1>next</h1>
    <table border="0">      
      <xsl:for-each select="Orders/Order">
        <tr>
          <td>
            <xsl:value-of select="CustomerName"/>
            <br/>
           
            <xsl:if test="DeliveryCompany != ''">
              <xsl:value-of select="DeliveryCompany"/>
              <br/>
            </xsl:if>

            <xsl:value-of select="DeliveryStreet1"/><br/>

            <xsl:if test="DeliveryStreet2 != ''">
              <xsl:value-of select="DeliveryStreet2"/>
              <br/>
            </xsl:if>

            <xsl:value-of select="DeliveryCity"/><br/>
            <xsl:value-of select="DeliveryPostalCode"/>
           
          </td>
        </tr>
      </xsl:for-each>

    </table>
    </body>
   </html>
  </xsl:template>

</xsl:stylesheet>

Open in new window

0
 
LVL 8

Expert Comment

by:Bob Hoffman
ID: 33531836
try adding  below
0
 

Author Comment

by:scm0sml
ID: 33531973
well i've now got:
<?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"/>
 
  <xsl:template match="/">
   
    <html>

      <head>
        <title></title>
      </head>

      <body>
        <h1>next</h1>
        <table border="0">
          <xsl:for-each select="Orders/Order">
            <tr>
              <td>
                <xsl:value-of select="CustomerName"/>
                <br/>

                <xsl:if test="DeliveryCompany != ''">
                  <xsl:value-of select="DeliveryCompany"/>
                  <br/>
                </xsl:if>

                <xsl:value-of select="DeliveryStreet1"/>
                <br/>

                <xsl:if test="DeliveryStreet2 != ''">
                  <xsl:value-of select="DeliveryStreet2"/>
                  <br/>
                </xsl:if>

                <xsl:value-of select="DeliveryCity"/>
                <br/>
                <xsl:value-of select="DeliveryPostalCode"/>

              </td>
            </tr>
          </xsl:for-each>

        </table>
      </body>
    </html>
  </xsl:template>

</xsl:stylesheet>


its not erroring anymore but itsn not displaying anything either? :(
0
 
LVL 8

Expert Comment

by:Bob Hoffman
ID: 33532402
By anything do you mean the "next" is not displaying or nothing at all is displaying? Can you post your transformation code.
0
 

Author Comment

by:scm0sml
ID: 33532545
before i made the cahnges in this post i was able to display the html table etc but was getting errors if i added a <h1> etc.

Now I can add the h1 without error but nothing at all is being displayed so i think the issue is def in the xslt.

I have reposted this below along with my transformation code.

Thanks

<?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"/>
 
  <xsl:template match="/">
   
    <html>

      <head>
        <title></title>
      </head>

      <body>
        <h1>next</h1>
        <table border="0">
          <xsl:for-each select="Orders/Order">
            <tr>
              <td>
                <xsl:value-of select="CustomerName"/>
                <br/>

                <xsl:if test="DeliveryCompany != ''">
                  <xsl:value-of select="DeliveryCompany"/>
                  <br/>
                </xsl:if>

                <xsl:value-of select="DeliveryStreet1"/>
                <br/>

                <xsl:if test="DeliveryStreet2 != ''">
                  <xsl:value-of select="DeliveryStreet2"/>
                  <br/>
                </xsl:if>

                <xsl:value-of select="DeliveryCity"/>
                <br/>
                <xsl:value-of select="DeliveryPostalCode"/>

              </td>
            </tr>
          </xsl:for-each>

        </table>
      </body>
    </html>
  </xsl:template>

</xsl:stylesheet>


here is the transform code from vb.net:
oXml.LoadXml(xml)

        oWriter = XmlWriter.Create(htmlFileName)
        resolver.Credentials = System.Net.CredentialCache.DefaultCredentials

        xsltrans.Load(Application.StartupPath & "\" & xsltFilename & ".xslt", Nothing, resolver)
        xsltrans.Transform(oXml, oWriter)
0
 
LVL 8

Expert Comment

by:Bob Hoffman
ID: 33532884
try it without the resolver, I don't believe you need this for what your doing.

xsltrans.Load(Application.StartupPath & "\" & xsltFilename & ".xslt")

what version of .net are you using?
0
 

Author Comment

by:scm0sml
ID: 33532996
2.0
0
 

Author Comment

by:scm0sml
ID: 33533016
removed the resolver but still no joy :(
0
 
LVL 8

Expert Comment

by:Bob Hoffman
ID: 33533168
Assuming your XML is good (you can open the XML file in IE and it looks good)

I would do this, create a simple aspx page in your sites root, put your XML and XSL files in the root as well

   

If this works then the issue is probably with the transformation code, if not it's probably the XML and XSL itself.
0
 

Author Comment

by:scm0sml
ID: 33540001
this is a windows based application.

bit of a breakthrough though. The html file I am creating doesnt show the output when opening or printing it, but if i view source it is all there!!

I've included the first few lines of the html as presumably this is where the problem is?

<?xml version="1.0" encoding="utf-8"?><html xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:z="#RowsetSchema"><head><title /></head><body>
        test
    <table><tr><td><img src="" alt="" /></td><td>
                Some address etc<br />
0
 

Author Comment

by:scm0sml
ID: 33540247
right i have found what the problem was.

i had my title tage <title></title>

But because it was emty it was bring transformed as <title/> and this meant that the html was displaying.

I have now put some dummy text in but is there a fix for this?
0
 
LVL 8

Accepted Solution

by:
Bob Hoffman earned 500 total points
ID: 33542873
remove it, you don't need it on a windows app, it won't show anyway.
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question