Re: [xsl] SV: xsl-list Digest 21 Apr 2006 05:10:00 -0000 Issue 753

Subject: Re: [xsl] SV: xsl-list Digest 21 Apr 2006 05:10:00 -0000 Issue 753
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 21 Apr 2006 12:04:53 -0400
Lisa,

You're running into trouble because when you call in your external document using the document() function, it is being parsed and made available as a source tree. Tags-n-text are gone.

In order to represent the tags-n-text (the XML file considered as literal data not as XML), you have a choice:

1. Preprocess the file to escape the markup. This is as simple as converting all occurrences of & to &amp; and all occurrences of < to &lt; (since those two characters are the "open markup delimiters"). Wrap it in an innocuous wrapper element so it can still be called in using document().

2. Call it in using document() and then using an XSLT "tag-writing" stylesheet (module) to write it out as markup again. (Find such a stylesheet by Evan Lenz at http://xmlportfolio.com/xml-to-string/.) This method is fairly quick-and-dirty and it's not perfect, as you won't get "tag fidelity" (that is, the pseudo-markup that gets written out won't look just like the markup that went in: attributes may come out in a different order, CDATA marked sections won't appear as such, etc.), but it's easy to implement and fits into an XSLT 1.0 framework without fussing.

3. Find or develop a way to call in the external file not as XML using document(), but as literal text. In other words, keep it away from the parser.

Fortunately for all of us, XSLT 2.0 now gives us a ready-made way to do no. 3: the unparsed-text() function. If XSLT 2.0 is an option for you, I recommend it. (I expect to be using that function quite a bit myself.)

Cheers,
Wendell

At 09:11 AM 4/21/2006, you wrote:
I am writing an XSL:FO document that will create a pdf document. One
chapter will contain an "example XML".

I access the XML file by a variable using document() function, and so
far so good. I now want to list the whole file tags, names, values and
all, pereferrably also indentaions.

When I try to list the whole XML file firstly, I try:

<xsl:for-each select="$SourceMetadata/*">
<!--List the XML file-->
<xsl:copy-of select="." />
</xsl:for-each>

This results in an error message saying: "Element name :
BusinessObjectName.(namespace = Null) Source context
unavailable.Unsupported element encountered".

The BusinessObjectName is the first element in the XML file.
The XML file does not contain any namespace.

I then try to add attribute copy-namespaces=No, then the parser says it
is wrong attribute for copy-of. Parser = Apache FOP.bat.

I change the code to:


<xsl:for-each select="$SourceMetadata/*"> <!--List the XML file--> <xsl:copy-of select="node()" /> </xsl:for-each>

Now I get all element values in a row. No element names and no tags.

I then change to:

<xsl:for-each select="$SourceMetadata/*">
<!--List the XML file-->
<xsl:copy-of select="name()/>
</xsl:for-each>

I then get all tag names in a row, no values, no tags.

What can I do?


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread