Re: [xsl] embedding XML in the value of attribute

Subject: Re: [xsl] embedding XML in the value of attribute
From: "Kurt Cagle" <cagle@xxxxxxxxx>
Date: Thu, 5 Jul 2001 16:26:50 -0700
Seconding Michael's comments on this --

The JSP syntax is not XML, even though it bears a passing resemblance to it.
If you are using JSP in this fashion - to pass the results of a Java class
to an output stream, however, it may be worth your while to recast the whole
page as an XML document  processed by an XSLT document with an appropriate
handler for the tag:

Your XML source document may then look like:

<html>
    <head>...</head>
    <body>
        <form ..>
            ....
             <larry:formclass id="myinput"
xmlns:larry="urn:schemas-larry-com:formclass"/>
    </body>
</html>

Your XSLT transformation may look like:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                      xmlns:larry="urn:schemas-larry-com:formclass">
    <script language="Java" src="larry.formclass"
implements-prefix="larry"/>

    <xsl:template match="/">
        <xsl:apply-templates select="*|@*|text()"/>
    </xsl:template>

    <xsl:template match="*|@*|text()">
        <xsl:apply-templates select="*|@*|text()"/>
    </xsl:template>

    <xsl:template match="larry:formclass>
        <input type="text" name="{@id}" value="{larry:getInput()}"/>
    </xsl:template>
</xsl:template>

The advantage to this approach is that you can also pass parameters to the
input type via attributes, something that is more problematic using JSP.
Take a look at Michael's superb book for more information on using extension
functions.

-- Kurt Cagle



----- Original Message -----
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Thursday, July 05, 2001 4:06 PM
Subject: RE: [xsl] embedding XML in the value of attribute


> It's a fundamental (and useful) feature of XSLT that a stylesheet is a
> well-formed XML document. In other words, no way!
>
> Mike Kay
> Software AG
>
> > -----Original Message-----
> > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of B. Tommie
> > Usdin
> > Sent: 05 July 2001 23:01
> > To: xsl-list
> > Subject: [xsl] embedding XML in the value of attribute
> >
> >
> >
> > >From: Larry_Mason@xxxxxx
> > >To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > >Subject: embedding XML in the value of attribute
> > >Date: Thu, 5 Jul 2001 15:00:42 -0500
> >
> > >I am trying to define a syntax that works in JSP and XSLT
> > where I compute
> > >the class for a tag given various conditions.  The following
> > syntax works
> > >in a JSP page using a custom tag for formclass.
> > >    <input type="text" class="<larry:formclass/>"/>
> > >
> > >I have a similar XSLT template for formclass.  However,
> > processing the
> > >syntax above in my XML feed complains about the < preceding
> > the namespace.
> > > If I change it to
> > >    <input type="text" class="&lt;larry:formclass/>"/>
> > >everything works fine.
> > >
> > >I would prefer identical syntax if possible [ note: the
> > first syntax must
> > >remain for the JSP to work properly ].  Any thoughts?
> > >
> > >If I can't "fix" it, I think I will suggest this syntax and recommend
> > >escaping the embeded less-than and greater-than symbols.
> > >    <input type="text" class="&lt;larry:formclass/&gt;"/>
> > >
> > >Cheers!
> > >Larry
> >
> > --
> > ======================================================================
> > B. Tommie Usdin                        mailto:btusdin@xxxxxxxxxxxxxxxx
> > Mulberry Technologies, Inc.
> > http://www.mulberrytech.com
> > 17 West Jefferson Street                           Phone: 301/315-9631
> > Suite 207                                    Direct Line: 301/315-9634
> > 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
> >
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>


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


Current Thread