Solved

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

Posted on 2006-06-23
7
736 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
  • 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now