In article <10**************************@posting.google.com >,
Martin <ms*****@csc.com> wrote:
% === INPUT-File in.xml
% <?xml version = '1.0'?>
% <person><who>scott</who></person>
%
% === Needed OUTPUT-File out.xml
% === Note: the format must be exactly this to be
% === processable by xsql using xsql-insert
% <?xml version = '1.0'?>
% <ROWSET><ROW>
% <NAME><person><who>scott</who></person></NAME>
% </ROW></ROWSET>
% === My xslt-File p.xsl, that misses the important fact
% === of replacing < with <
% <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
% version="1.0">
% <xsl:output method="xml" omit-xml-declaration="yes"/>
% <xsl:template match="@*|node()">
% <xsl:element name="ROWSET">
% <xsl:element name="ROW">
% <xsl:element name="NAME">
% <xsl:copy-of select="."/>
% </xsl:element>
% </xsl:element>
% </xsl:element>
% </xsl:template>
% </xsl:stylesheet>
You should keep in mind that the output of the XSLT process is a tree,
not just text. When you use copy-of, what you're doing is copying the
tree structure related to the node, not the tags themselves.
So, how do you get the tags? Probably node-by-node, using the name()
function. If all you want is a copy of the original document with
< and & escaped, I'm not sure XSLT is the best thing to use, but
let's have an untested go at it
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<!-- need to handle elements, pis, comments, and attributes separately
since we need to format the tags. We start with elements -->
<xsl:template match="*">
<!-- no need for xsl:element here, so let's not use it -->
<ROWSET>
<ROW>
<NAME>
<xsl:text><</xsl:text>
<xsl:value-of select="name()"/>
<!-- attributes go here -->
<xsl:for-each select="@*">
<xsl:value-of select='name()'/.
<xsl:text>='</xsl:text>
<!-- you might need to deal with quotes here -->
<xsl:value-of select='.'/.
<xsl:text>'</xsl:text>
</xsl:for-each>
<xsl:text>></xsl:text>
<xsl:apply-templates/>
<xsl:text></</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>></xsl:text>
</NAME>
</ROW>
</ROWSET>
</xsl:template>
<xsl:template match="processing-instruction()">
<xsl:text><?</xsl:text>
<xsl:value-of select='name()'/>
<xsl:text> </xsl:text>
<xsl:value-of select='.'/>
<xsl:text>?></xsl:text>
</xsl:template>
<xsl:template match="comment()">
<xsl:text><-- </xsl:text>
<xsl:value-of select='.'/>
<xsl:text> --></xsl:text>
</xsl:template>
</xsl:stylesheet>
--
Patrick TJ McPhee
East York Canada
pt**@interlog.com