xsl-list
[Top] [All Lists]

Re: converting XML to XML problem

2003-11-11 09:08:34
Dear Wendell,
Thanks much. Your solution
<xsl:template match="node2">
  <xsl:text disable-output-escaping="yes">
   &amp;
  </xsl:text>
<xsl:value-of select="@attr/>;
</xsl:template>

works for me. Yes I am trying to generate entity
references on the fly. Actually my soucr xml is
generated by one module and then I need to convert
that source to this one meaning the source will
contain the entity names as a value of an attribute. I
will use those values as to reference to the entities.
The output from this conversion will then be used by
another module. Hence I need to have & character in my
output. I am using XMLSPY and it does support the
feature you said. 
Thanks a lot.
Abhi



--- Wendell Piez <wapiez(_at_)mulberrytech(_dot_)com> wrote:
Abhijit,

It looks like you are trying to generate entity
references on the fly, 
which is against the XSLT processing paradigm.
Entities are part of XML 
considered as a lexical object (string of characters
including markup), 
whereas XSLT operates on XML considered as a parsed
data object (a tree of 
nodes). Once the document has been parsed into this
tree, all entities have 
been resolved. Likewise, most XSLT serializers do
not provide any means for 
generating entity references instead of the
whatever-it-is that they refer to.

Since most XSLT processors can serialize their
output, however (i.e., since 
most, in practice, write their output as marked-up
text to a file), there 
is a workaround that *may* be available to you.

So instead of

<xsl:template match="node2">
&amp;<xsl:value-of select="@attr/>;
</xsl:template>

try

<xsl:template match="node2">
   <xsl:text
disable-output-escaping="yes">&amp;</xsl:text>
   <xsl:value-of select="@attr/>;
</xsl:template>

and see if it works better for you.

Note that is ONLY works if your XSLT transformation
is directly followed by 
a serialization (i.e. you are writing your output as
a stream of characters 
somewhere), and if your processor implements this
optional feature of the 
language.

It will NOT work in many pipeline architectures or
in some processors that 
are built to ply the straight-and-narrow, such as
the Transformiix 
processor used in Mozilla.

So beware! this is a trick you should use knowing
the risks.

-- Wendell

At 06:13 PM 11/10/2003, you wrote:
Hi,
I am using xsl for xml to xml tranformation. I want
to
pring & character in my output xml....




======================================================================
Wendell Piez                           
mailto:wapiez(_at_)mulberrytech(_dot_)com
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

======================================================================


 XSL-List info and archive: 
http://www.mulberrytech.com/xsl/xsl-list



__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list