Solved

XSL/XML/XHTML: Include XML content and write to XHTML

Posted on 2006-06-23
7
752 Views
Last Modified: 2013-12-16
Hi Gertone,

we have the following XSL scriptlet:

<xsl:variable name="webDescription" select="/Root/Object/ExternalReferences/Keyword[Characteristic='ZPDB_WEBDESCRIPTION']/Value"/>
<xsl:variable name="webDescriptionParsed" select="translate($webDescription, '\', '/')"/>
<xsl:copy-of select="document($webDescriptionParsed)"/>

Basically, it will read an XML file from the file server and should include the HTML content to the XHTML output stream.

The XHTML from XSL engine is as follows:

...
              <html>      
                <p>bla bla</p>      
              </html>
...

The XHTML 1.0 Strict validator has a problem with html/xmlns missiong and <P> not allowed.

Is there a trick how the XML header should look like so that HTML will be displayed and validated or should the XML file be addressed with XPath - but how to apply the format tags then?!

Ciao

0
Comment
Question by:go4java
[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
  • 4
  • 3
7 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16968512
Hi go4java,

likely you can just put the namespace declaration in your snippet already
like this
<html xmlns="http://www.w3.org/1999/xhtml"

in xhtml strict <p> cannot be a child of <html>
you need at least a body tag

change your snippert to this and try again
              <html xmlns="http://www.w3.org/1999/xhtml">
                <body>    
                <p>bla bla</p>
                </body>    
              </html>


Cheers!
0
 

Author Comment

by:go4java
ID: 16968652
The XML now looks like that:

<?xml version="1.0" encoding="ISO-8859-1"?>
<html xmlns="http://www.w3.org/1999/xhtml">
  <body>
     <p>...</p>
  </body>      
</html>

The HTML output is:

              <html>  
                <body>      
                  <p>...</p>  
                </body>
              </html>

...and if I run the XSL as mentioned above, the XHTML strict 1.0 returnes the following errors:

- xmlns missing
- html not allowed
- body not allowed


0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16969827
go4java,
> <xsl:copy-of select="document($webDescriptionParsed)"/>

just a quick guess
did you try this?
<xsl:copy-of select="document($webDescriptionParsed)//html"/>
it might help you keep the namespace declaration
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

Author Comment

by:go4java
ID: 16981796
unfortunately not...
0
 

Author Comment

by:go4java
ID: 16981886
I've removed <html> and <body>  from the input XML and inserted only a <div>-tag as root.
The result by the XHTML strict validator is as follows:

<div xmlns="">
xmlns is not allowed!

xmlns has automatically been inserted?!

Ciao


0
 

Author Comment

by:go4java
ID: 16990231
Hi Gertone,
we're able to manage like that:

<?xml version="1.0" encoding="ISO-8859-1"?>
<div xmlns="http://www.w3.org/1999/xhtml">
      <p>...</p>
</div>

0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 16990336
sorry, missed your message yesterday

> xmlns has automatically been inserted?!

yes, since you did not give the xhtml namespace with the <div> element,
the XSLT assumes you want it in the NULL namespace, so it is switched off by xmlns=""
by adding the namespace in the <div> you remain in the same namespace and likely the namespace node is not copied

If this validates well, that means you already had a <html><body> in the output before copying in your snippet

If you want the HTML snippets to be valid documents on their own,
you can leave the <html> and <body> in the snippet
and have your copy like this
<xsl:copy-of select="document($webDescriptionParsed)//html/body/node()"/>
or in order not to fight with all the namespace declarations
<xsl:copy-of select="document($webDescriptionParsed)//*[local-name() = 'html']/*[local-name() = 'body']/node()"/>
The ability to validate snippets can come in handy if the snippets become complex

just a thought
cheers

Geert

0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Make Line Items Look Good Over Mobile 2 127
removing a class in javascript 4 97
xslt 1.0 - How to split value 8 51
.NET XML to Dictionary - XML has repeating node names 8 31
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

752 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