xsl-list
[Top] [All Lists]

RE: xsl:copy, mode and source code

2004-08-27 11:11:54
Are you using xsl:output method="text"? If you are, you will have to
generate any XML tags you want in the output "by hand".

Michael Kay 

-----Original Message-----
From: Dave Jarvis [mailto:djarvis(_at_)invoqsystems(_dot_)com] 
Sent: 27 August 2004 18:06
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] xsl:copy, mode and source code

Hello,

I must simplify Java/C source code into a high-level XML 
representation 
(which is transformed into source code).  I've hit a snag and would 
really appreciate some help.

Consider the following XML, within the "axe" namespace:

   <axe:message type="response">
     <pingResult><axe:value-of select="pingOutput" /></pingResult>
   </axe:message>

The "axe:message" content can contain XML code or text:

   <axe:message type="response">
     <nesting level="1">
       <pingResult><axe:value-of select="pingOutput" /></pingResult>
     </nesting>
   </axe:message>

The relevant XSL templates include:

   <xsl:template match="axe:message[(_at_)type='response']">
     AGENT_m.append( <xsl:apply-templates mode="response" /> );
   </xsl:template>

   <xsl:template match="@*|node()" mode="response">
     X<xsl:copy><xsl:apply-templates select="@*|node()" /></xsl:copy>
   </xsl:template>

   <xsl:template match="*" mode="response">
     Y<xsl:apply-templates />
   </xsl:template>

   <!-- Used by "axe:var", but may be applicable here ... -->
   <xsl:template match="*|text()">
     "<xsl:copy-of select="." />"
     <xsl:if test="position() != last()">+</xsl:if>
   </xsl:template>

The result from debugging the template:

     AGENT_m.append(
     X
     X
     Y
     AGENT_pingOutput );

The desired result:

     AGENT_m.append(
     "<pingResult>" +
     AGENT_pingOutput +
     "</pingResult>" );

I could try an ugly hack:

   <xsl:template match="@*|node()">
     "&lt;<xsl:value-of select="name()" />&gt;"+
     <xsl:apply-templates /> +
     "&lt;/<xsl:value-of select="name()" />&gt;"
   </xsl:template>

I've also tried xsl:copy-of (for a deep copy), and 
xsl:for-each over all 
elements, but no matter what I do, I just can't seem to make 
<pingResult> appear (much less in quotes with concatentation).  I've 
read numerous FAQs, a few mailing lists, and searched Google. 
 After two 
days of wrestling, I'm stumped; everything I've read leads me 
to believe 
that <pingResult> should appear -- but it doesn't!

Is there an elegant solution?

Many thanks for any ideas, or smacks along the upside of my head.

Sincerely,
Dave Jarvis

P.S.
I'm using libxslt from http://xmlsoft.org/XSLT/.

--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--





<Prev in Thread] Current Thread [Next in Thread>