Hi Peter,
I get error when processing the stylesheet. It errors here.
<xsl:for-each select="registration[count(.|key('entry',company
[1])=1]">
specifically:
Expression does not return a DOM node.
registration[-->count(.|key('entry',company[1])=1]<--
Ideas?
Thanks,
Chris
"Peter Flynn" <pe********@m.silmaril.ie> wrote in message
news:3n*************@individual.net... Chris Kettenbach wrote:
Good Morning, Sorry for xposting. Just need a liitle help. I have an xml file that's generated from a database. How do I select distinct values from a field
XML doesn't have fields -- the database did but this isn't a database any more. In XML they're called elements (they've got a lot in common with fields but they ain't the same).
in xslt and then loop through the records and produce output.
It looks like you need to process the information grouped by company name, and there's a technique in XSLT 1.0 for doing this called Muenchian grouping (it won't be needed in XSLT 2 because that has a built-in group-processing command, but XSLT 2 is not a Recommendation yet).
Check the XSLT FAQ for "Muenchian" to find examples.
///Peter
[Group and followup corrected to comp.text.xml]
Example
<registrations> <registration> <company>Awesome Printers</company> <first>John</first> <last>Smith</last> </registration> <registration> <company>Awesome Printers</company> <first>Bob</first> <last>Roberts</last> </registration> <registration> <company>Awesome Printers</company> <first>John</first> <last>Johnson</last> </registration> <registration> <company>Other Company</company> <first>Tom</first> <last>Thomas</last> </registration> <registration> <company>Other Company</company> <first>Dan</first> <last>Daniels</last> </registration> </registrations> ++++++++++++++++++++++++++++++++++++++++++++++++ I want the out put to be something like this
<table> <tr> <td>Company Name</td> <td>Employees</td> </tr> <tr> <td>Awesome Printers</td> <td>John Smith<br/> Bob Roberts<br/> John Johnson<br/></td> </tr> <tr> <td>Other Company</td> <td>Tom Thomas<br/> Dan Daniels<br/></td> </tr> </table>
Effectively writing unique company names once and then putting only the employees from that company into the employee table cell.
If you scrolled down this far then you've been rewarded :-)
The trick is to use lookup keys to test the selected group of elements against, in order to pick only the first ocurrence in each group; then output the group header at that point; and only then go and process all the elements in the group to extract the detail from each of them.
The syntax is tricky because it's very compact. It selects all registration elements, but subjects each of them to the test that [the number of nodes in the union of (the current node and the first node with the current company value returned by the lookup) is equal to 1] -- in effect meaning they are one and the same node, ie the first in their company name grouping. You'll probably need to read that 3 or 4 times -- it took me a week to grok it.
<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:key name="entry" match="registration" use="company"/>
<xsl:template match="/"> <html> <head> <title>Registrations</title> </head> <body> <xsl:apply-templates/> </body> </html> </xsl:template>
<xsl:template match="registrations"> <table> <xsl:for-each select="registration[count(.|key('entry',company [1])=1]"> <xsl:sort select="company"/> <tr> <th valign="top"> <xsl:value-of select="company"/> </th> <td valign="top"> <xsl:for-each select="key('entry',current()/company)"> <xsl:sort select="last"/> <xsl:value-of select="first"/> <xsl:text> </xsl:text> <xsl:value-of select="last"/> <xsl:if test="position()!=last()"> <br/> </xsl:if> </xsl:for-each> </td> </tr> </xsl:for-each> </table> </xsl:template>
</xsl:stylesheet>
///Peter 4 1809
Unbalanced left <--> right parenthenses
"Chris Kettenbach" <in**@piasd.net> wrote in message
news:QY********************@giganews.com... Hi Peter, I get error when processing the stylesheet. It errors here.
<xsl:for-each select="registration[count(.|key('entry',company [1])=1]">
specifically:
Expression does not return a DOM node. registration[-->count(.|key('entry',company[1])=1]<--
Ideas?
Thanks, Chris
"Peter Flynn" <pe********@m.silmaril.ie> wrote in message news:3n*************@individual.net... Chris Kettenbach wrote:
Good Morning, Sorry for xposting. Just need a liitle help. I have an xml file that's generated from a database. How do I select distinct values from a field
XML doesn't have fields -- the database did but this isn't a database any more. In XML they're called elements (they've got a lot in common with fields but they ain't the same).
in xslt and then loop through the records and produce output.
It looks like you need to process the information grouped by company name, and there's a technique in XSLT 1.0 for doing this called Muenchian grouping (it won't be needed in XSLT 2 because that has a built-in group-processing command, but XSLT 2 is not a Recommendation yet).
Check the XSLT FAQ for "Muenchian" to find examples.
///Peter
[Group and followup corrected to comp.text.xml]
Example
<registrations> <registration> <company>Awesome Printers</company> <first>John</first> <last>Smith</last> </registration> <registration> <company>Awesome Printers</company> <first>Bob</first> <last>Roberts</last> </registration> <registration> <company>Awesome Printers</company> <first>John</first> <last>Johnson</last> </registration> <registration> <company>Other Company</company> <first>Tom</first> <last>Thomas</last> </registration> <registration> <company>Other Company</company> <first>Dan</first> <last>Daniels</last> </registration> </registrations> ++++++++++++++++++++++++++++++++++++++++++++++++ I want the out put to be something like this
<table> <tr> <td>Company Name</td> <td>Employees</td> </tr> <tr> <td>Awesome Printers</td> <td>John Smith<br/> Bob Roberts<br/> John Johnson<br/></td> </tr> <tr> <td>Other Company</td> <td>Tom Thomas<br/> Dan Daniels<br/></td> </tr> </table>
Effectively writing unique company names once and then putting only the employees from that company into the employee table cell.
If you scrolled down this far then you've been rewarded :-)
The trick is to use lookup keys to test the selected group of elements against, in order to pick only the first ocurrence in each group; then output the group header at that point; and only then go and process all the elements in the group to extract the detail from each of them.
The syntax is tricky because it's very compact. It selects all registration elements, but subjects each of them to the test that [the number of nodes in the union of (the current node and the first node with the current company value returned by the lookup) is equal to 1] -- in effect meaning they are one and the same node, ie the first in their company name grouping. You'll probably need to read that 3 or 4 times -- it took me a week to grok it.
<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:key name="entry" match="registration" use="company"/>
<xsl:template match="/"> <html> <head> <title>Registrations</title> </head> <body> <xsl:apply-templates/> </body> </html> </xsl:template>
<xsl:template match="registrations"> <table> <xsl:for-each select="registration[count(.|key('entry',company [1])=1]"> <xsl:sort select="company"/> <tr> <th valign="top"> <xsl:value-of select="company"/> </th> <td valign="top"> <xsl:for-each select="key('entry',current()/company)"> <xsl:sort select="last"/> <xsl:value-of select="first"/> <xsl:text> </xsl:text> <xsl:value-of select="last"/> <xsl:if test="position()!=last()"> <br/> </xsl:if> </xsl:for-each> </td> </tr> </xsl:for-each> </table> </xsl:template>
</xsl:stylesheet>
///Peter
Do you have an example of how it should look?
Thanks for your help.
Chris
"Dimitre Novatchev" <di******@tpg.com.au> wrote in message
news:43***********************@authen.white.readfr eenews.net... Unbalanced left <--> right parenthenses "Chris Kettenbach" <in**@piasd.net> wrote in message news:QY********************@giganews.com... Hi Peter, I get error when processing the stylesheet. It errors here.
<xsl:for-each select="registration[count(.|key('entry',company [1])=1]">
specifically:
Expression does not return a DOM node. registration[-->count(.|key('entry',company[1])=1]<--
Ideas?
Thanks, Chris
"Peter Flynn" <pe********@m.silmaril.ie> wrote in message news:3n*************@individual.net... Chris Kettenbach wrote:
Good Morning, Sorry for xposting. Just need a liitle help. I have an xml file that's generated from a database. How do I select distinct values from a field
XML doesn't have fields -- the database did but this isn't a database any more. In XML they're called elements (they've got a lot in common with fields but they ain't the same).
in xslt and then loop through the records and produce output.
It looks like you need to process the information grouped by company name, and there's a technique in XSLT 1.0 for doing this called Muenchian grouping (it won't be needed in XSLT 2 because that has a built-in group-processing command, but XSLT 2 is not a Recommendation yet).
Check the XSLT FAQ for "Muenchian" to find examples.
///Peter
[Group and followup corrected to comp.text.xml]
Example
<registrations> <registration> <company>Awesome Printers</company> <first>John</first> <last>Smith</last> </registration> <registration> <company>Awesome Printers</company> <first>Bob</first> <last>Roberts</last> </registration> <registration> <company>Awesome Printers</company> <first>John</first> <last>Johnson</last> </registration> <registration> <company>Other Company</company> <first>Tom</first> <last>Thomas</last> </registration> <registration> <company>Other Company</company> <first>Dan</first> <last>Daniels</last> </registration> </registrations> ++++++++++++++++++++++++++++++++++++++++++++++++ I want the out put to be something like this
<table> <tr> <td>Company Name</td> <td>Employees</td> </tr> <tr> <td>Awesome Printers</td> <td>John Smith<br/> Bob Roberts<br/> John Johnson<br/></td> </tr> <tr> <td>Other Company</td> <td>Tom Thomas<br/> Dan Daniels<br/></td> </tr> </table>
Effectively writing unique company names once and then putting only the employees from that company into the employee table cell.
If you scrolled down this far then you've been rewarded :-)
The trick is to use lookup keys to test the selected group of elements against, in order to pick only the first ocurrence in each group; then output the group header at that point; and only then go and process all the elements in the group to extract the detail from each of them.
The syntax is tricky because it's very compact. It selects all registration elements, but subjects each of them to the test that [the number of nodes in the union of (the current node and the first node with the current company value returned by the lookup) is equal to 1] -- in effect meaning they are one and the same node, ie the first in their company name grouping. You'll probably need to read that 3 or 4 times -- it took me a week to grok it.
<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:key name="entry" match="registration" use="company"/>
<xsl:template match="/"> <html> <head> <title>Registrations</title> </head> <body> <xsl:apply-templates/> </body> </html> </xsl:template>
<xsl:template match="registrations"> <table> <xsl:for-each select="registration[count(.|key('entry',company [1])=1]"> <xsl:sort select="company"/> <tr> <th valign="top"> <xsl:value-of select="company"/> </th> <td valign="top"> <xsl:for-each select="key('entry',current()/company)"> <xsl:sort select="last"/> <xsl:value-of select="first"/> <xsl:text> </xsl:text> <xsl:value-of select="last"/> <xsl:if test="position()!=last()"> <br/> </xsl:if> </xsl:for-each> </td> </tr> </xsl:for-each> </table> </xsl:template>
</xsl:stylesheet>
///Peter
"Chris Kettenbach" <in**@piasd.net> wrote in message
news:8_********************@giganews.com... Do you have an example of how it should look? Thanks for your help. Chris
I am not a compiler, but I have developed a tool that may help -- use the
XPath Visualizer to play with XPath and learn it the fun way.
Cheers,
Dimitre Novatchev
P.S. By not answering your question and directing you to serious
self-training with the XPath Visualizer I am actually saving you a lot of
time -- just try it and you'll see :o)
"Dimitre Novatchev" <di******@tpg.com.au> wrote in message news:43***********************@authen.white.readfr eenews.net... Unbalanced left <--> right parenthenses "Chris Kettenbach" <in**@piasd.net> wrote in message news:QY********************@giganews.com... Hi Peter, I get error when processing the stylesheet. It errors here.
<xsl:for-each select="registration[count(.|key('entry',company [1])=1]">
specifically:
Expression does not return a DOM node. registration[-->count(.|key('entry',company[1])=1]<--
Ideas?
Thanks, Chris
"Peter Flynn" <pe********@m.silmaril.ie> wrote in message news:3n*************@individual.net... Chris Kettenbach wrote:
> Good Morning, > Sorry for xposting. Just need a liitle help. > I have an xml file that's generated from a database. How do I select > distinct values from a field
XML doesn't have fields -- the database did but this isn't a database any more. In XML they're called elements (they've got a lot in common with fields but they ain't the same).
> in xslt and then loop through the records and > produce output.
It looks like you need to process the information grouped by company name, and there's a technique in XSLT 1.0 for doing this called Muenchian grouping (it won't be needed in XSLT 2 because that has a built-in group-processing command, but XSLT 2 is not a Recommendation yet).
Check the XSLT FAQ for "Muenchian" to find examples.
///Peter
[Group and followup corrected to comp.text.xml]
> Example > > <registrations> > <registration> > <company>Awesome Printers</company> > <first>John</first> > <last>Smith</last> > </registration> > <registration> > <company>Awesome Printers</company> > <first>Bob</first> > <last>Roberts</last> > </registration> > <registration> > <company>Awesome Printers</company> > <first>John</first> > <last>Johnson</last> > </registration> > <registration> > <company>Other Company</company> > <first>Tom</first> > <last>Thomas</last> > </registration> > <registration> > <company>Other Company</company> > <first>Dan</first> > <last>Daniels</last> > </registration> > </registrations> > ++++++++++++++++++++++++++++++++++++++++++++++++ > I want the out put to be something like this > > <table> > <tr> > <td>Company Name</td> > <td>Employees</td> > </tr> > <tr> > <td>Awesome Printers</td> > <td>John Smith<br/> > Bob Roberts<br/> > John Johnson<br/></td> > </tr> > <tr> > <td>Other Company</td> > <td>Tom Thomas<br/> > Dan Daniels<br/></td> > </tr> > </table> > > Effectively writing unique company names once and then putting only > the > employees from that company into the employee table cell.
If you scrolled down this far then you've been rewarded :-)
The trick is to use lookup keys to test the selected group of elements against, in order to pick only the first ocurrence in each group; then output the group header at that point; and only then go and process all the elements in the group to extract the detail from each of them.
The syntax is tricky because it's very compact. It selects all registration elements, but subjects each of them to the test that [the number of nodes in the union of (the current node and the first node with the current company value returned by the lookup) is equal to 1] -- in effect meaning they are one and the same node, ie the first in their company name grouping. You'll probably need to read that 3 or 4 times -- it took me a week to grok it.
<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:key name="entry" match="registration" use="company"/>
<xsl:template match="/"> <html> <head> <title>Registrations</title> </head> <body> <xsl:apply-templates/> </body> </html> </xsl:template>
<xsl:template match="registrations"> <table> <xsl:for-each select="registration[count(.|key('entry',company [1])=1]"> <xsl:sort select="company"/> <tr> <th valign="top"> <xsl:value-of select="company"/> </th> <td valign="top"> <xsl:for-each select="key('entry',current()/company)"> <xsl:sort select="last"/> <xsl:value-of select="first"/> <xsl:text> </xsl:text> <xsl:value-of select="last"/> <xsl:if test="position()!=last()"> <br/> </xsl:if> </xsl:for-each> </td> </tr> </xsl:for-each> </table> </xsl:template>
</xsl:stylesheet>
///Peter
Dimitre Novatchev wrote: Unbalanced left <--> right parenthenses
Quite right, it looks like something chewed off the closing parenthesis.
I pasted the code from the working file, so it may have been garbled in
transmission. The line should read
<xsl:for-each select="registration[count(.|key('entry',company)[1])=1]">
(that too is cut'n'paste so if that gets screwed, I'm sorry).
///Peter
"Chris Kettenbach" <in**@piasd.net> wrote in message news:QY********************@giganews.com... Hi Peter, I get error when processing the stylesheet. It errors here.
<xsl:for-each select="registration[count(.|key('entry',company [1])=1]">
specifically:
Expression does not return a DOM node. registration[-->count(.|key('entry',company[1])=1]<--
Ideas?
Thanks, Chris
"Peter Flynn" <pe********@m.silmaril.ie> wrote in message news:3n*************@individual.net... Chris Kettenbach wrote:
Good Morning, Sorry for xposting. Just need a liitle help. I have an xml file that's generated from a database. How do I select distinct values from a field
XML doesn't have fields -- the database did but this isn't a database any more. In XML they're called elements (they've got a lot in common with fields but they ain't the same).
in xslt and then loop through the records and produce output.
It looks like you need to process the information grouped by company name, and there's a technique in XSLT 1.0 for doing this called Muenchian grouping (it won't be needed in XSLT 2 because that has a built-in group-processing command, but XSLT 2 is not a Recommendation yet).
Check the XSLT FAQ for "Muenchian" to find examples.
///Peter
[Group and followup corrected to comp.text.xml]
Example
<registrations> <registration> <company>Awesome Printers</company> <first>John</first> <last>Smith</last> </registration> <registration> <company>Awesome Printers</company> <first>Bob</first> <last>Roberts</last> </registration> <registration> <company>Awesome Printers</company> <first>John</first> <last>Johnson</last> </registration> <registration> <company>Other Company</company> <first>Tom</first> <last>Thomas</last> </registration> <registration> <company>Other Company</company> <first>Dan</first> <last>Daniels</last> </registration> </registrations> ++++++++++++++++++++++++++++++++++++++++++++++++ I want the out put to be something like this
<table> <tr> <td>Company Name</td> <td>Employees</td> </tr> <tr> <td>Awesome Printers</td> <td>John Smith<br/> Bob Roberts<br/> John Johnson<br/></td> </tr> <tr> <td>Other Company</td> <td>Tom Thomas<br/> Dan Daniels<br/></td> </tr> </table>
Effectively writing unique company names once and then putting only the employees from that company into the employee table cell.
If you scrolled down this far then you've been rewarded :-)
The trick is to use lookup keys to test the selected group of elements against, in order to pick only the first ocurrence in each group; then output the group header at that point; and only then go and process all the elements in the group to extract the detail from each of them.
The syntax is tricky because it's very compact. It selects all registration elements, but subjects each of them to the test that [the number of nodes in the union of (the current node and the first node with the current company value returned by the lookup) is equal to 1] -- in effect meaning they are one and the same node, ie the first in their company name grouping. You'll probably need to read that 3 or 4 times -- it took me a week to grok it.
<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:key name="entry" match="registration" use="company"/>
<xsl:template match="/"> <html> <head> <title>Registrations</title> </head> <body> <xsl:apply-templates/> </body> </html> </xsl:template>
<xsl:template match="registrations"> <table> <xsl:for-each select="registration[count(.|key('entry',company [1])=1]"> <xsl:sort select="company"/> <tr> <th valign="top"> <xsl:value-of select="company"/> </th> <td valign="top"> <xsl:for-each select="key('entry',current()/company)"> <xsl:sort select="last"/> <xsl:value-of select="first"/> <xsl:text> </xsl:text> <xsl:value-of select="last"/> <xsl:if test="position()!=last()"> <br/> </xsl:if> </xsl:for-each> </td> </tr> </xsl:for-each> </table> </xsl:template>
</xsl:stylesheet>
///Peter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Derek Fountain |
last post by:
I've been wading through the O'Reilly XSLT book. All seemed OK and sensible
until I got to the "programming" bit - variables, loops, conditions and so
on.
Do people actually use this stuff for...
|
by: Tom Corcoran |
last post by:
I am working to ease updating of a html page by transforming 2 xml files. I
was going to use xslt for this and had bought 2 unopened books, wrox xslt
and o'reilly's xslt cookbook. But am now...
|
by: valued customer |
last post by:
What do you think is the future of efforts to reduce the "verbosity"
of XSLT, ostensibly by people who have had years of experience working
with this technology?
(example site)...
|
by: Chris Kettenbach |
last post by:
Good Morning,
Sorry for xposting. Just need a liitle help.
I have an xml file that's generated from a database. How do I select
distinct values from a field in xslt and then loop through the...
|
by: darrel |
last post by:
I eventually want to pass a variable to my XSLT file, but, for now, I'm just
trying to be able to declare it globally in the XSLT file itself.
So, I added this to the top of the page:
...
|
by: Gordon Moore |
last post by:
Hi,
I'm new to using xml/xslt and although I can create an xml document
using the dataset.WriteXml statement, and I have created an xslt to
transform the xml into the output I want, I have to...
|
by: Thierry |
last post by:
Let's say I have the following tags in an xml:
<World>
<Country>Canada</Country>
<Hemisphere>North</Hemisphere>
<Weather climate="cold" forecast="snow">
<CommandAction>$(HOME)\calculate.py...
|
by: Dormilich |
last post by:
Hi,
I'm testing my classes for a web page and I stumble upon an error I don't have a clue what it means:
Error:
Fatal error: Can't use method return value in write context in "output.php" on...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |