XML/XSL parsing problems! 
Author Message
 XML/XSL parsing problems!

I have the following code (test code) that opens XML(XHTML content) and XSL,
parses,  and writes it into the page:

==============================
<script language="C#" runat="server">
     protected void Page_Load(Object sender, EventArgs e) {
        DoXML();
     }

     private void DoXML() {
        parseXmlXsl("default.xml","content.xsl");
     }

     public void parseXmlXsl(String theXml, String theXsl) {
        XPathDocument doc = new XPathDocument(Server.MapPath(theXml));
        XslTransform trans = new XslTransform();
        trans.Load(Server.MapPath(theXsl));

        StringWriter sw2 = new StringWriter();
        XmlTextWriter xmlWriter = new XmlTextWriter(sw2);
        trans.Transform(doc,null,xmlWriter);
        theContent.InnerHtml = sw2.ToString();
        sw2.Close();
        xmlWriter.Close();
     }
</script>
<span id="theContent" runat="server"></span>
==============================

This works fine, but although the xsl has the output tag as:
<xsl:output method="html" indent="yes" omit-xml-declaration="yes" />

It still turns <br /> tags in the XML into <br></br> in the output, which
I'm pretty sure it's not supposed to do.

The XSL is a simple apply-templates with the usual HTML tags:
<xsl:template match="/"><xsl:apply-templates/></xsl:template>

<xsl:template match="text()"><xsl:value-of select="."/></xsl:template>

<xsl:template match="a"><xsl:element name="a"><xsl:if








n
t></xsl:template>

etc.etc.etc.

Thanks.

--
:::BOB:::
"Son, when you participate in sporting events, its not whether you win or
lose ... its how drunk you get."
-Homer Simpson



Fri, 19 Nov 2004 23:04:56 GMT  
 XML/XSL parsing problems!
Got some of it figured. In the matching for the break tag...

<xsl:template match="br"><xsl:element name="br"><xsl:if


... if the test for the clear attribute is in, the HTML output is <br></br>,
even when there is no break tag. But if I remove the test all-together...

<xsl:template match="br"><xsl:element
name="br"></xsl:element></xsl:template>

...then the output is <br />. This kind of sucks since the clear attribute
is needed, and I'd also like to put others in like style and class just in
case. Has anyone else had this problem at all?

--
::BOB::
"Let us celebrate our agreement with the adding of chocolate to milk."
- Homer Simpson

Quote:
> I have the following code (test code) that opens XML(XHTML content) and
XSL,
> parses,  and writes it into the page:

> ==============================
> <script language="C#" runat="server">
>      protected void Page_Load(Object sender, EventArgs e) {
>         DoXML();
>      }

>      private void DoXML() {
>         parseXmlXsl("default.xml","content.xsl");
>      }

>      public void parseXmlXsl(String theXml, String theXsl) {
>         XPathDocument doc = new XPathDocument(Server.MapPath(theXml));
>         XslTransform trans = new XslTransform();
>         trans.Load(Server.MapPath(theXsl));

>         StringWriter sw2 = new StringWriter();
>         XmlTextWriter xmlWriter = new XmlTextWriter(sw2);
>         trans.Transform(doc,null,xmlWriter);
>         theContent.InnerHtml = sw2.ToString();
>         sw2.Close();
>         xmlWriter.Close();
>      }
> </script>
> <span id="theContent" runat="server"></span>
> ==============================

> This works fine, but although the xsl has the output tag as:
> <xsl:output method="html" indent="yes" omit-xml-declaration="yes" />

> It still turns <br /> tags in the XML into <br></br> in the output, which
> I'm pretty sure it's not supposed to do.

> The XSL is a simple apply-templates with the usual HTML tags:
> <xsl:template match="/"><xsl:apply-templates/></xsl:template>

> <xsl:template match="text()"><xsl:value-of select="."/></xsl:template>

> <xsl:template match="a"><xsl:element name="a"><xsl:if




n

- Show quoted text -

Quote:
> t></xsl:template>

> etc.etc.etc.

> Thanks.

> --
> :::BOB:::
> "Son, when you participate in sporting events, its not whether you win or
> lose ... its how drunk you get."
> -Homer Simpson



Fri, 19 Nov 2004 23:18:56 GMT  
 XML/XSL parsing problems!
Bob,

    My only guess would be that the transformation engine is trying to be a
little smart here.  When applying the template, it sees that the xsl:element
tag has children, and therefore assumes that the element might have it's own
children and gerates the two-tag structure ahead of time.  However, because
your if condition makes it so that content could exist, as opposed to always
existing, you get the <br></br> formatting.

    Does it really matter though?  I mean, when processing, they both mean
the same thing.

--
               - Nicholas Paldino [.NET MVP]


Quote:
> Got some of it figured. In the matching for the break tag...

> <xsl:template match="br"><xsl:element name="br"><xsl:if


> ... if the test for the clear attribute is in, the HTML output is
<br></br>,
> even when there is no break tag. But if I remove the test all-together...

> <xsl:template match="br"><xsl:element
> name="br"></xsl:element></xsl:template>

> ...then the output is <br />. This kind of sucks since the clear attribute
> is needed, and I'd also like to put others in like style and class just in
> case. Has anyone else had this problem at all?

> --
> ::BOB::
> "Let us celebrate our agreement with the adding of chocolate to milk."
> - Homer Simpson

> > I have the following code (test code) that opens XML(XHTML content) and
> XSL,
> > parses,  and writes it into the page:

> > ==============================
> > <script language="C#" runat="server">
> >      protected void Page_Load(Object sender, EventArgs e) {
> >         DoXML();
> >      }

> >      private void DoXML() {
> >         parseXmlXsl("default.xml","content.xsl");
> >      }

> >      public void parseXmlXsl(String theXml, String theXsl) {
> >         XPathDocument doc = new XPathDocument(Server.MapPath(theXml));
> >         XslTransform trans = new XslTransform();
> >         trans.Load(Server.MapPath(theXsl));

> >         StringWriter sw2 = new StringWriter();
> >         XmlTextWriter xmlWriter = new XmlTextWriter(sw2);
> >         trans.Transform(doc,null,xmlWriter);
> >         theContent.InnerHtml = sw2.ToString();
> >         sw2.Close();
> >         xmlWriter.Close();
> >      }
> > </script>
> > <span id="theContent" runat="server"></span>
> > ==============================

> > This works fine, but although the xsl has the output tag as:
> > <xsl:output method="html" indent="yes" omit-xml-declaration="yes" />

> > It still turns <br /> tags in the XML into <br></br> in the output,
which
> > I'm pretty sure it's not supposed to do.

> > The XSL is a simple apply-templates with the usual HTML tags:
> > <xsl:template match="/"><xsl:apply-templates/></xsl:template>

> > <xsl:template match="text()"><xsl:value-of select="."/></xsl:template>

> > <xsl:template match="a"><xsl:element name="a"><xsl:if



> > name="name"><xsl:value-of


n

- Show quoted text -

Quote:
> > t></xsl:template>

> > etc.etc.etc.

> > Thanks.

> > --
> > :::BOB:::
> > "Son, when you participate in sporting events, its not whether you win
or
> > lose ... its how drunk you get."
> > -Homer Simpson



Fri, 19 Nov 2004 23:22:14 GMT  
 XML/XSL parsing problems!
Bob,

Quote:
> I have the following code (test code) that opens XML(XHTML content) and
XSL,
> parses,  and writes it into the page:

Just out of curiosity: What happens if you add a
    <xsl:output method="html"/>
To your template? Does it help?

--
Tomas Restrepo



Sat, 20 Nov 2004 00:09:31 GMT  
 XML/XSL parsing problems!
The XSL has the <xsl:output there with method-"html".

Just did a text with a normal ASP page and it comes out fine. <br /> tags
become <br> tags, but with .NET <br /> tags become <br></br>. Same with
other tags like <img /> and <hr /> as well, they all come out with end tags.
No big whoop except that browsers see <br></br> as 2 break tags, all other
tags that and up having an end tag work fine. <hr></hr> is shown as one
hardrule when the page is rendered.

Seems like a .NET parser bug, since I know that the SDK says that <br/> is
supposed to come out as <br>.

=)

--
:::BOB:::
"Kids, just because I don't care doesn't mean I'm not listening."
- Homer Simpson



Quote:
> Bob,

> > I have the following code (test code) that opens XML(XHTML content) and
> XSL,
> > parses,  and writes it into the page:

> Just out of curiosity: What happens if you add a
>     <xsl:output method="html"/>
> To your template? Does it help?

> --
> Tomas Restrepo




Sat, 20 Nov 2004 02:17:27 GMT  
 XML/XSL parsing problems!
Can you provide the XML document and XSLT stylesheet that showed this
problem.

PS: Next time, please do not crosspost. XSLT questions about the .NET
framework can be answered in
microsoft.public.dotnet.xml

--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> I have the following code (test code) that opens XML(XHTML content) and
XSL,
> parses,  and writes it into the page:

> ==============================
> <script language="C#" runat="server">
>      protected void Page_Load(Object sender, EventArgs e) {
>         DoXML();
>      }

>      private void DoXML() {
>         parseXmlXsl("default.xml","content.xsl");
>      }

>      public void parseXmlXsl(String theXml, String theXsl) {
>         XPathDocument doc = new XPathDocument(Server.MapPath(theXml));
>         XslTransform trans = new XslTransform();
>         trans.Load(Server.MapPath(theXsl));

>         StringWriter sw2 = new StringWriter();
>         XmlTextWriter xmlWriter = new XmlTextWriter(sw2);
>         trans.Transform(doc,null,xmlWriter);
>         theContent.InnerHtml = sw2.ToString();
>         sw2.Close();
>         xmlWriter.Close();
>      }
> </script>
> <span id="theContent" runat="server"></span>
> ==============================

> This works fine, but although the xsl has the output tag as:
> <xsl:output method="html" indent="yes" omit-xml-declaration="yes" />

> It still turns <br /> tags in the XML into <br></br> in the output, which
> I'm pretty sure it's not supposed to do.

> The XSL is a simple apply-templates with the usual HTML tags:
> <xsl:template match="/"><xsl:apply-templates/></xsl:template>

> <xsl:template match="text()"><xsl:value-of select="."/></xsl:template>

> <xsl:template match="a"><xsl:element name="a"><xsl:if




n

- Show quoted text -

Quote:
> t></xsl:template>

> etc.etc.etc.

> Thanks.

> --
> :::BOB:::
> "Son, when you participate in sporting events, its not whether you win or
> lose ... its how drunk you get."
> -Homer Simpson



Sat, 20 Nov 2004 12:36:04 GMT  
 XML/XSL parsing problems!
Because of the client I can't post the XML, but it is just a:
<ContentRoot>
    XHTML content in here
</ContentRoot>

And the XSL is a simple XSL with template matching for every HTML tag and
attribute like the example in the previous message showed.

There's nothing wrong with cross-posting, especially when the question spans
multiple categories like mine did. I had an XML/XSL part to my question and
a C# part to my question, "StringWriter sw2 = new StringWriter();"......

:::BOB:::
"Bart, a woman is like a beer. They look good, they smell good, and you'd
step over your own mother just to get one! (chugs beer)"
- Homer Simpson

Quote:
> Can you provide the XML document and XSLT stylesheet that showed this
> problem.

> PS: Next time, please do not crosspost. XSLT questions about the .NET
> framework can be answered in
> microsoft.public.dotnet.xml



> > I have the following code (test code) that opens XML(XHTML content) and
> XSL,
> > parses,  and writes it into the page:

> > ==============================
> > <script language="C#" runat="server">
> >      protected void Page_Load(Object sender, EventArgs e) {
> >         DoXML();
> >      }

> >      private void DoXML() {
> >         parseXmlXsl("default.xml","content.xsl");
> >      }

> >      public void parseXmlXsl(String theXml, String theXsl) {
> >         XPathDocument doc = new XPathDocument(Server.MapPath(theXml));
> >         XslTransform trans = new XslTransform();
> >         trans.Load(Server.MapPath(theXsl));

> >         StringWriter sw2 = new StringWriter();
> >         XmlTextWriter xmlWriter = new XmlTextWriter(sw2);
> >         trans.Transform(doc,null,xmlWriter);
> >         theContent.InnerHtml = sw2.ToString();
> >         sw2.Close();
> >         xmlWriter.Close();
> >      }
> > </script>
> > <span id="theContent" runat="server"></span>
> > ==============================

> > This works fine, but although the xsl has the output tag as:
> > <xsl:output method="html" indent="yes" omit-xml-declaration="yes" />

> > It still turns <br /> tags in the XML into <br></br> in the output,
which
> > I'm pretty sure it's not supposed to do.

> > The XSL is a simple apply-templates with the usual HTML tags:
> > <xsl:template match="/"><xsl:apply-templates/></xsl:template>

> > <xsl:template match="text()"><xsl:value-of select="."/></xsl:template>

> > <xsl:template match="a"><xsl:element name="a"><xsl:if



> > name="name"><xsl:value-of


n

- Show quoted text -

Quote:
> > t></xsl:template>

> > etc.etc.etc.

> > Thanks.



Sun, 21 Nov 2004 00:08:50 GMT  
 XML/XSL parsing problems!
Only problem is that browsers see <br></br> as 2 break tags instead of one.

--
:::BOB:::
"Nobody gets into heaven without a glowstick."
- Homer Simpson



Quote:
> Bob,

>     My only guess would be that the transformation engine is trying to be
a
> little smart here.  When applying the template, it sees that the
xsl:element
> tag has children, and therefore assumes that the element might have it's
own
> children and gerates the two-tag structure ahead of time.  However,
because
> your if condition makes it so that content could exist, as opposed to
always
> existing, you get the <br></br> formatting.

>     Does it really matter though?  I mean, when processing, they both mean
> the same thing.

> --
>                - Nicholas Paldino [.NET MVP]



> > Got some of it figured. In the matching for the break tag...

> > <xsl:template match="br"><xsl:element name="br"><xsl:if


> > ... if the test for the clear attribute is in, the HTML output is
> <br></br>,
> > even when there is no break tag. But if I remove the test
all-together...

> > <xsl:template match="br"><xsl:element
> > name="br"></xsl:element></xsl:template>

> > ...then the output is <br />. This kind of sucks since the clear
attribute
> > is needed, and I'd also like to put others in like style and class just
in
> > case. Has anyone else had this problem at all?

> > --
> > ::BOB::
> > "Let us celebrate our agreement with the adding of chocolate to milk."
> > - Homer Simpson

> > > I have the following code (test code) that opens XML(XHTML content)
and
> > XSL,
> > > parses,  and writes it into the page:

> > > ==============================
> > > <script language="C#" runat="server">
> > >      protected void Page_Load(Object sender, EventArgs e) {
> > >         DoXML();
> > >      }

> > >      private void DoXML() {
> > >         parseXmlXsl("default.xml","content.xsl");
> > >      }

> > >      public void parseXmlXsl(String theXml, String theXsl) {
> > >         XPathDocument doc = new XPathDocument(Server.MapPath(theXml));
> > >         XslTransform trans = new XslTransform();
> > >         trans.Load(Server.MapPath(theXsl));

> > >         StringWriter sw2 = new StringWriter();
> > >         XmlTextWriter xmlWriter = new XmlTextWriter(sw2);
> > >         trans.Transform(doc,null,xmlWriter);
> > >         theContent.InnerHtml = sw2.ToString();
> > >         sw2.Close();
> > >         xmlWriter.Close();
> > >      }
> > > </script>
> > > <span id="theContent" runat="server"></span>
> > > ==============================

> > > This works fine, but although the xsl has the output tag as:
> > > <xsl:output method="html" indent="yes" omit-xml-declaration="yes" />

> > > It still turns <br /> tags in the XML into <br></br> in the output,
> which
> > > I'm pretty sure it's not supposed to do.

> > > The XSL is a simple apply-templates with the usual HTML tags:
> > > <xsl:template match="/"><xsl:apply-templates/></xsl:template>

> > > <xsl:template match="text()"><xsl:value-of select="."/></xsl:template>

> > > <xsl:template match="a"><xsl:element name="a"><xsl:if



> > > name="name"><xsl:value-of







n

- Show quoted text -

Quote:
> > > t></xsl:template>

> > > etc.etc.etc.

> > > Thanks.

> > > --
> > > :::BOB:::
> > > "Son, when you participate in sporting events, its not whether you win
> or
> > > lose ... its how drunk you get."
> > > -Homer Simpson



Fri, 03 Dec 2004 23:49:36 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. XML + XSL => Outlook

2. ATL COM... apply xsl to xml

3. XML-XSL->HTML

4. starting MSIE out of Visual C++ with parameters: XML file and XSL file

5. starting MSIE out of Visual C++ with parameters: XML file and XSL file

6. XML-XSL->HTML

7. XML/XSL support on device

8. XML / XSL -- PPC 2002 -- An interesting Query ??!!

9. Design question concerning XML/XSL

10. C#, SQL XML, XSL example please

11. system.xml.xsl - missing from beta 1 ?

12. how to create XML with XSL stylesheet

 

 
Powered by phpBB® Forum Software