Given is a XHTML File, which includes a few tables. This code is the part I am trying to grab:
<div class="table-wrapper">
<table class="menu-table">
<tbody>
<tr class="menu-table-row">
<td>Tellergericht
<div class="icon-tellergericht" title="Tellergericht"></div>
<div class="icon-rind" title="Rind"></div>
<div class="icon-schwein" title="Schwein"></div>
</td>
<td>Ausgabe</td>
<td>Student</td>
<td>Mitarbeiter</td>
<td>Gast</td>
</tr>
<tr>
<td>Brötchen <sup>(9,G,A)</sup></td>
<td>Veg</td>
<td>0,45 €</td>
<td>0,60 €</td>
<td>0,60 €</td>
</tr>
Here is the complete code: https://pastebin.com/wTNA7qgY
Therefore I have the following XLS code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:sp="http://www.example.com/speiseplan" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<!-- root element matching -->
<xsl:template match="/">
<xsl:message>Debug: Entering root template</xsl:message>
<sp:speiseplan>
<xsl:apply-templates select="//div[@class='table-wrapper']/table[@class='menu-table']"/>
</sp:speiseplan>
</xsl:template>
<!-- menu table matching -->
<xsl:template match="//div[@class='table-wrapper']/table[@class='menu-table']">
<xsl:message>Debug: Extracted date - <xsl:value-of select="preceding::div[@class='csc-textpic-text'][1]"/></xsl:message>
<sp:gericht tag="{preceding::div[@class='csc-textpic-text'][1]}">
<xsl:apply-templates select="tbody/tr[position() > 1]"/>
</sp:gericht>
</xsl:template>
<!-- row matching -->
<xsl:template match="tbody/tr">
<xsl:message>Debug: Extracted name - <xsl:value-of select="normalize-space(td[1])"/></xsl:message>
<xsl:message>Debug: Extracted allergene - <xsl:value-of select="normalize-space(substring-before(substring-after(td[1],'('),')'))"/></xsl:message>
<xsl:message>Debug: Extracted student price - <xsl:value-of select="normalize-space(td[3])"/></xsl:message>
<sp:gericht>
<sp:name>
<xsl:value-of select="normalize-space(td[1])"/>
</sp:name>
<sp:zusatzstoffe>
<sp:allergene>
<xsl:value-of select="normalize-space(substring-before(substring-after(td[1],'('),')'))"/>
</sp:allergene>
</sp:zusatzstoffe>
<sp:preis student="{normalize-space(td[3])}" mitarbeiter="{normalize-space(td[4])}" gast="{normalize-space(td[5])}"/>
</sp:gericht>
</xsl:template>
</xsl:stylesheet>
To transform the XHTML I was given Saxon HE 12.4 and the following command to execute:
java -cp SaxonHE12-4J/saxon-he-12.4.jar net.sf.saxon.Transform -s:Mensa-Stralsund-14.12.2023.xhtml -xsl:transform.xsl -o:Mensa-Stralsund-14.12.2023.xml
This results in the only message Entering root template.
My guess was, that the XPath variables were wrong, but when I checked in a Online XPath tester, it gave me the right results immediately.
I tried to just test the XPath query with saxon: java -cp SaxonHE12-4J/saxon-he-12.4.jar net.sf.saxon.Query -s:Mensa-Stralsund-14.12.2023.xhtml -qs:"//div[@class='table-wrapper']/table[@class='menu-table']", but it didn't work neither.
What could be my problem? Thanks a lot for your time. Happy holidays