This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: generalizing an XSL solution


Perfect!  Thank you!

Judi

----- Original Message -----
From: Mike Brown <mbrown@corp.webb.net>
To: <xsl-list@mulberrytech.com>
Sent: Tuesday, February 15, 2000 5:22 PM
Subject: RE: generalizing an XSL solution


> > I want to create an XSL sheet that selects specific
> > information from an HTML table and writes it to an XML file.
> > For example I might have an HTML document with 4 tables on
> > it, and I want the information from  rows 3,4, and 5 of
> > table 2.    (assume that the HTML is well formed)
> >
> > I can figure out how to do this for specific instances
> > (using siblings/children and XPath).  What I want to do is
> > create a sheet that has the parameters (3,4,5 and 2 in this
> > example) specified separately
>
> You almost described it exactly. You just need to get the syntax right.
> Let's say your XHTML is in sometables.xhtml, and you have info about what
> table and row numbers you want in a file called lookup.xml:
>
> <?xml version="1.0" encoding="utf-8"?>
> <stuff_we_want>
>   <tablerow num="3" fromtable="2"/>
>   <tablerow num="4" fromtable="2"/>
>   <tablerow num="5" fromtable="2"/>
> </stuff_we_want>
>
> then in a template in your stylesheet, you could have:
>
> <!-- process each tablerow from lookup.xml -->
> <xsl:for-each select="document('lookup.xml')/stuff_we_want/tablerow"/>
>   <!-- get table and row -->
>   <xsl:variable name="tablenum" select="number(@fromtable)"/>
>   <xsl:variable name="rownum" select="number(@num)"/>
>   <!-- copy contents of 2nd cell from that row -->
>   <xsl:copy-of
>
select="document('sometables.xhtml')//table[$tablenum]/tr[$rownum]/td[2]"/>
> </xsl:for-each>
>
> As you can see, you just use the number() function to make the $tablenum
and
> $rownum variables be numbers rather than node-sets or strings, and then
use
> those numbers in predicates in an XPath expression to select the nth node
in
> the set identified to the left of the predicate.
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]