You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Michael Lepine <ML...@TRISECT.com> on 2000/04/12 05:30:29 UTC
xsl question
Disclaimer: I looked to post this to say a xalan-users@xml.apache.org list,
but didn't see anything comparable, so I hope this is the right place to
post.
I currently have tags like these in my xsl template so I can create
corresponding html form tags for the named element:
<xsl:apply-templates select="element[@name='fname']"/>
<xsl:apply-templates select="element[@name='lname']"/>
I have a template that I use for all my generic html form element
generation, so I would have the following code snippets to match the above,
then forward them on to the build_element template:
<xsl:template match="element[@name='fname']">
<xsl:call-template name="build_element"/>
</xsl:template>
<xsl:template match="element[@name='lname']">
<xsl:call-template name="build_element"/>
</xsl:template>
This seems so redundant (mainly because it is). Is there a wildcard that I
could match off of so I could basically replace the 2 <xsl:template
match...> tags above with something like:
<xsl:template match="element[@name=*]">
<xsl:call-template name="build_element"/>
</xsl:template>
This just returns all the child nodes and that's, so I just don't know
enough about xsl to know if what I want to do is possible.
Any and all feedback is warmly welcomed.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Michael Lépine - Staff Developer
Trisect (www.trisect.com)
2030 Powers Ferry Rd., Suite 121
Atlanta, GA 30339
w: 770.850.9858 ext. 1510
c: 404.915.2756
mlepine@trisect.com
XSL: howto test if an element have a child ?
Posted by Benoit Fouche <b....@cross-systems.com>.
Hi !
I am currently applying XSL stylesheet to an XML doc to generate WML (=HTML
for WAP)
My XML doc looks like this (and must be like this, I can't change the
structure nor the attributes...) :
<!--source.xml-->
<portal>
<select name="sites">
<option url="http://www.yahoo.com">Yahoo</option>
...
<option url="http://www.caramail.com">Caramail</option>
</select>
<select name="prefixes">
<option value="prefix">Mr.</option>
<option value="prefix">Mrs.</option>
...
</select>
<select name="activities" multiple="true">
<option value="activity">sport</option>
<option value="activity">cinema</option>
...
</select>
</portal>
In the tag option, you can have several differents attributes, so I would
like to make a test on those attribute like this:
I would like to do the following algorithm in XSL:
For all the "select/option" tag where the option@url DOESN'T exists I would
like to output a copy of the select tag:
<select (with the EXACT copy of the attributes of select tag)>
<option value=...>
</select>
And for the "select/option" tag where the option@url exists I just want to
output a link:
<a href=value-of select="@url">value-of option</a>
(without the "select" tag, here is the problem...)
My steelsheet looks like this, but doesn't work (parser crashes...) :
<xsl:template match="option[@url]">
<a><xsl:attribute name="href"><xsl:value-of
select="@onpick"/></xsl:attribute>
<xsl:value-of/>
</a>
</xsl:template>
<xsl:template match="select">
<xsl:choose>
<xs:when test="option[@url]"/>
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="*|@*|comment()|pi()|text)"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
any help would be great !
Ben.
Re: xsl question
Posted by Dan Morrison <dm...@es.co.nz>.
Michael Lepine wrote:
> I currently have tags like these in my xsl template so I can create
> corresponding html form tags for the named element:
<xsl:template match="element[@name='fname']">
<xsl:call-template name="build_element"/>
</xsl:template>
UIML eh?
I had a look at that recently. Personally I don't think much of the
structure. It looks very biased in the direction of C/C++ engineers, as
opposed to the encapsulated way XML is more suited to. I hate to have
the properties of an object declared somewhere other that the object
itself. The 'lookup table' way that UIML marks its classes bugs me.
I'd advise having a look at XwingML, which although it has its own bias
towards Java, is a much nicer structure.
I'm currently working on a (PERL) UI manager that is close to both
UIML's shortcut syntax and XwingML. It's fun 'skinning' those old ugly
HTML forms, and giving my CGIs an easy interface API.
Sorry I dunno about Xalan, but in some parsers you can do it
<xsl:template match="element">
<xsl:call-template name="{@name}"/>
</xsl:template>
.dan.
:=====================:====================:
: Dan Morrison : The Web Limited :
: http://here.is/dan : http://web.co.nz :
: dman@es.co.nz : danm@web.co.nz :
: 04 384 1472 : 04 495 8250 :
: 025 207 1140 : :
:.....................:....................:
: If ignorance is bliss, why aren't more people happy?
:.........................................:
Re: xsl question
Posted by David Blondeau <bl...@exoffice.com>.
Hello Michael
<stuff remove>
> I have a template that I use for all my generic html form element
> generation, so I would have the following code snippets to match the
above,
> then forward them on to the build_element template:
>
> <xsl:template match="element[@name='fname']">
> <xsl:call-template name="build_element"/>
> </xsl:template>
>
> <xsl:template match="element[@name='lname']">
> <xsl:call-template name="build_element"/>
> </xsl:template>
>
> This seems so redundant (mainly because it is). Is there a wildcard that I
> could match off of so I could basically replace the 2 <xsl:template
> match...> tags above with something like:
>
> <xsl:template match="element[@name=*]">
> <xsl:call-template name="build_element"/>
> </xsl:template>
I think you can replace your match by only one doing :
<xsl:template match="element[@name='fname' or @name='lname']">
<xsl:call-template name="build_element"/>
</xsl:template>
If you want all the elements that have an attribute "name", just do:
<xsl:template match="element[@name]">
...
<stuff removed>
Hope that helps
David