xsl-list
[Top] [All Lists]

RE: Apply-templates - how to omit top level element tags?

2005-09-08 11:22:40
Mike,

At 07:32 PM 9/7/2005, you wrote:
Also, why is it not possible to be able to output:

        FooXXX

When you start with

        <Name>Foo<myns:MyX></Name>

It is possible.

Where the XSL has this:

        <xsl:template match="myns:MyX">XXX</xsl:template>

I either get:

        <Name>FooXXX</Name>

Or just:

        Foo

But not what I want, which is:

        FooXXX

You haven't shown us the template matching "Name".

Combined with your template above, this template

<xsl:template match="Name">
  <xsl:apply-templates/>
</xsl:template>

will result in

FooXXX

but this template

<xsl:template match="Name">
  <xsl:copy>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

will result in

<Name>FooXXX</Name>

while

<xsl:template match="Name">
  <BANG>
    <xsl:apply-templates/>
  </BANG>
</xsl:template>

will result in

<BANG>FooXXX</BANG>

Why do I have to write a specific template to accomplish this?  In the
case above I want to output the value contained in <Name> that way only
once, but I also want the write of the XML to be able to embed other
references into it that I can parse with apply-templates.

As near as I can understand it, you are asking the XSLT to do something it does quite naturally. But it's hard to determine what your actual criteria are from this description.

Having to create a template for a single case is like having to write a
function in Java called Add37(x) simply to add 37 to the variable "x" in
only one place in the code.  Why can't I just do it inline rather than
have to worry about logic in two places and also worry about potential
sideaffects or name collisions? Is it because XSL simply doesn't provide
such a capability?

Again, I'm not sure of the actual problem here. XSLT provides a "for-each" instruction to allow you to avoid writing templates that are only used once, in a single context. But I suspect that's actually a red herring in your case.

If the problem isn't yet solved, could we trouble you to repost a demonstration?

Cheers,
Wendell


======================================================================
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
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>