Subject: Re: [xsl] Attribute Matching From: "Karl Stubsjoen" <kstubs@xxxxxxxxx> Date: Sun, 7 Jan 2007 16:26:29 -0700 |
Beautiful! I may be forced to convert to a node result from this:
<xsl:template match="row"> <line> <xsl:apply-templates select="@*"> <xsl:with-param name="fields" select=" ../../fields/field"/> </xsl:apply-templates> </line> </xsl:template>
<xsl:variable name="drvr"> <xsl:apply-templates select="@*"> <xsl:with-param name="fields" select=" ../../fields/field"/> </xsl:apply-templates> </xsl:variable>
And then to use the variable drvr in the current row node, I'll need to reference it with a node-set conversion.
I'll give this a try. Was hoping to avoid the node-set conversion, but I'm not unfamiliar with this approach.
Karl Stubsjoen wrote:possible contre les messages non sollicitis
Hi
> In a single source of XML I have a FIELDS/FIELD lookup, where there > are many FIELD elements which may or may not have a flg attribute > who's value maps to an attribute of the same name in a row element. > The value of this attribute determines whether or not to include the > FIELD element in the result.
> So, I'll expand a little with my XML:
> <root> > <fields> > <field name="Name" flg="flgName"/> > <field name="HomeTown" flg="flgHomeTown"/> > <field name="Country" flg="flgCountry"/> > </fields> > <result> > <row flgHomeTown="1" flgCountry="0" flgName="0"/> > <row flgHomeTown="1" flgCountry="0" flgName="1"/> > </result> > </root>
So you are using XSLT 1.0? The following is what your are looking for, if I correctly understood:
(drkm)[31] ~/xslt/tests$ cat karl.xsl <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="/"> <res> <xsl:apply-templates select="root/result/row"/> </res> </xsl:template>
<xsl:template match="row"> <line> <xsl:apply-templates select="@*"> <xsl:with-param name="fields" select=" ../../fields/field"/> </xsl:apply-templates> </line> </xsl:template>
<xsl:template match="row/@*[. = '0']"> <xsl:param name="fields"/> </xsl:template>
<xsl:template match="row/@*[. = '1']"> <xsl:param name="fields"/> <xsl:variable name="name" select="name()"/> <xsl:copy-of select="$fields[@flg = $name]"/> </xsl:template>
</xsl:stylesheet>
(drkm)[32] ~/xslt/tests$ cat karl.xml <root> <fields> <field name="Name" flg="flgName"/> <field name="HomeTown" flg="flgHomeTown"/> <field name="Country" flg="flgCountry"/> </fields> <result> <row flgHomeTown="1" flgCountry="0" flgName="0"/> <row flgHomeTown="1" flgCountry="0" flgName="1"/> </result> </root>
(drkm)[33] ~/xslt/tests$ saxon karl.xml karl.xsl Warning: at xsl:stylesheet on line 3 of karl.xsl: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor <?xml version="1.0" encoding="UTF-8"?> <res> <line> <field name="HomeTown" flg="flgHomeTown"/> </line> <line> <field name="HomeTown" flg="flgHomeTown"/> <field name="Name" flg="flgName"/> </line> </res>
(drkm)[34] ~/xslt/tests$ xsltproc karl.xsl karl.xml <?xml version="1.0"?> <res> <line> <field name="HomeTown" flg="flgHomeTown"/> </line> <line> <field name="HomeTown" flg="flgHomeTown"/> <field name="Name" flg="flgName"/> </line> </res>
(drkm)[35] ~/xslt/tests$
Regards,
--drkm
__________________________________________________ Do You Yahoo!? En finir avec le spam? Yahoo! Mail vous offre la meilleure protection
http://mail.yahoo.fr Yahoo! Mail
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Attribute Matching, Florent Georges | Thread | [xsl] NMTOKENS and xsl:key, Houghton,Andrew |
Re: [xsl] NMTOKENS and xsl:key, David Carlisle | Date | RE: [xsl] NMTOKENS and xsl:key, Michael Kay |
Month |