for-each query won´t work
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 4
- Joined: Fri Dec 13, 2019 1:32 am
for-each query won´t work
Hello together,
I want to make a query, that shows me every informations about all highshools in one country.
In the following you can see what I´ve tried, but for some reason I get the following error:
Beschreibung: Leading '/' selects nothing: the context item is not a node
Furthermore, if I want to sort the highschools by name, I get the following error too:
A sequence of more than one item is not allowed as the @select attribute of xsl:sort (text("Havard"), text("Oxford University"), text("Stanford University")).
AuslandVKoenigreich.xsl
Part of the associated XML file:
What am I doing wrong, what do I need to change so that it works fine?
Best regards,
Tobi.
I want to make a query, that shows me every informations about all highshools in one country.
In the following you can see what I´ve tried, but for some reason I get the following error:
Beschreibung: Leading '/' selects nothing: the context item is not a node
Furthermore, if I want to sort the highschools by name, I get the following error too:
A sequence of more than one item is not allowed as the @select attribute of xsl:sort (text("Havard"), text("Oxford University"), text("Stanford University")).
AuslandVKoenigreich.xsl
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head>
<title>Kontrollblatt Nummer 3</title>
</head>
<body>
<h1><xsl:value-of select="./titel"/></h1>
<h2>Alle Studiengänge</h2>
<!--Abfrage Nummer 1-->
<table border="1">
<tr><th>Auslandshochschule ID</th><th>Name</th><th>Land</th><th>Adresse</th><th>Ort</th><th>URL</th></tr>
<xsl:for-each select="//AuslandsHochschulen/Auslandshochschule/[land='Vereinigtes Königreich']">
<xsl:sort select="//AuslandsHochschulen/name/text()"/>
<tr><td><xsl:value-of select="//AuslandsHochschulen/AuslandsHochschulID/text()"/></td>
<td> <xsl:value-of select="//AuslandsHochschulen/name/text()"/></td>
<td> <xsl:value-of select="//AuslandsHochschulen/land/text()"/></td>
<td> <xsl:value-of select="//AuslandsHochschulen/adresse/text()"/></td>
<td> <xsl:value-of select="//AuslandsHochschulen/ort/text()"/></td>
<td> <xsl:value-of select="//AuslandsHochschulen/url/text()"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Code: Select all
<studentenverwaltung
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="StudentenverwaltungXSD2.xsd">
<AuslandsHochschulen>
<AuslandsHochschulID>H01</AuslandsHochschulID>
<name>Havard</name>
<land>Vereinigte Staaten</land>
<adresse>MA</adresse>
<ort>Cambridge</ort>
<url>https://www.harvard.edu/</url>
</AuslandsHochschulen>
<AuslandsHochschulen>
<AuslandsHochschulID>H02</AuslandsHochschulID>
<name>Oxford University</name>
<land>Vereinigtes Königreich</land>
<adresse>Oxford OX1 2JD</adresse>
<ort>Oxford</ort>
<url>http://www.ox.ac.uk//</url>
</AuslandsHochschulen>
<AuslandsHochschulen>
<AuslandsHochschulID>H03</AuslandsHochschulID>
<name>Stanford University</name>
<land>Vereinigtes Königreich</land>
<adresse>450 Serra Mall</adresse>
<ort>Stanford</ort>
<url>https://www.stanford.edu/</url>
</AuslandsHochschulen>
</studentenverwaltung>
Best regards,
Tobi.
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: for-each query won´t work
Hi,
Try:
You'll also want to remove the "//AuslandsHochschulen/" part of the XPath from the inner xsl:value-of/@select.
e.g.
Regards,
Adrian
Try:
Code: Select all
<xsl:for-each select="//AuslandsHochschulen[land='Vereinigtes Königreich']">
e.g.
Code: Select all
<xsl:value-of select="AuslandsHochschulID/text()"/>
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service