|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
xsl and document( ) for external files and sorting - help needed
hi there. ok. here is the problem...
i have a main database xml file that looks like this <CODE> <?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="sort.xsl" ?> <!DOCTYPE list SYSTEM "maindb.dtd"> <list> <taxpayer id="js" file="johnsmith.xml"/> <taxpayer id="dj" file="davejones.xml"/> <taxpayer id="rt" file="roberttilley.xml"/> <taxpayer id="ec" file="edchinn.xml"/> <taxpayer id="sm" file="sammorton.xml"/> <taxpayer id="pd" file="philderuyter.xml"/> <taxpayer id="ck" file="chantelleknoetze.xml"/> <taxpayer id="bm" file="benmorton.xml"/> <taxpayer id="pp" file="peterparker.xml"/> <taxpayer id="am" file="alexmoody.xml"/> </list> </CODE> and each taxpayer refers to another external file file as shown, like <CODE> <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE taxpayer SYSTEM "taxpayer.dtd"> <taxpayer id="bm" > <name> <family>morton</family> <given>ben</given> </name> <address number="27" postcode="RH110LN"> <line1>cherrytree lane</line1> <line2>filed close</line2> <city>crawley</city> </address> <phone>01293521336</phone> <email>benmorton@home.com</email> <income salary="3000" allowance="6000"/> </taxpayer> </CODE> now, the xsl file associated with the main database xml file is used to sort the taxpayers names alphabetically and output the result to a new xml file. i just cant seem to get it to see the external files and process the names in them!!!!! its really doing my head in. the sort xsl file looks like this: <CODE> <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml"/> <xsl:include href="resultstyle.xsl"/> <!-- Template for root rule --> <xsl:template match="/"> <!-- call the stylesheet for the resulting table--> <xsl:call-template name="resultstyle"/> <xsl:apply-templates/> </xsl:template> <xsl:template match="list"> <h1>Sorting taxpayers by name in ascending order</h1> <!-- Table Header Creation --> <table border="1"> <tr> <th>Surname</th> <th>Firstname</th> </tr> <xsl:for-each select="document(@file)//taxpayer/name"> <xsl:sort order="ascending" select="family"/> <tr> <td> <xsl:value-of select="family"/> </td> <td> <xsl:value-of select="given"/> </td> </tr> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet> </CODE> please please can someone help me asap. thanks alot in advance bennyboy79 Last edited by bennyboy79 : December 5th, 2003 at 10:07 AM. |
|
#2
|
|||
|
|||
|
I hate to break it to you but this code:
Code:
select="document(@file)//taxpayer/name" ... will *never* work using standard XSL. You can't pass an attribute value into an XPATH this way, it isn't supported. I'm wondering why you need to make life so complicated? It would be so much easier to put all the taxpayers into a single XML file! You wouldn't need to use the document function at all *and* you could perform proper sorting on the data inside the taxpayers XML. document() is one of those convenient little fucntions that promises more than it can deliver. If your application relies on document() then you're probably doing something wrong ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > xslt and document( ) for external files and sorting |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|