Project

Profile

Help

Support #6521

closed

Node not matching when not in "pretty print"

Added by Justin Roegner 28 days ago. Updated 28 days ago.

Status:
Closed
Priority:
Low
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2024-08-29
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

Description

Match always found for ancestor::*[matches(@visibleWhen, '.*!=\s?null')][1] = current() when the source document matching elements are not separated by a text node.

This is the stripped down source xml:

<?xml version="1.0" encoding="UTF-8"?>
<cages><FileRoot name="Page1.xml"><content visibleWhen="level1 != null"><content visibleWhen="level2 != null"><content visibleWhen="level3 != null"><property name="standalone_prop"/></content></content></content></FileRoot></cages>

This is the xslt:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html" indent="yes"/>
	<xsl:template match="/">
		<html>
			<head>
				<style>
				
					table {
					  width: 100%;
					  border: 1px solid #ddd;
					}
					
					.subtable tr:nth-child(even) {
					  background-color: #eee;
					}
					
					.headerbg {
					  background-color: #ffff66;
					}
					
					.subtablehighlight tr:hover {background-color: #ffffe6;}
					
					.column1 {
						width: 80px;
					}
					
					fieldset {
						margin-bottom: 30px;
					}
					
				</style>
			</head>
			<body>
				<h1>Visible When</h1>
				<!-- Select all files -->
				<xsl:apply-templates select="//FileRoot"/>
			</body>
		</html>
	</xsl:template>
   
	<xsl:template match="FileRoot">
		<!-- Main section per file -->
		<fieldset>
			<!-- File name -->
			<legend><xsl:value-of select="./@name"/></legend>
			<!-- Only grab parent visibleWhen elements; children get addressed within the parent -->
			<xsl:apply-templates select="descendant::*[matches(@visibleWhen, '.*!=\s?null.*') and not(contains(string-join(ancestor::*/local-name(), ' '), ./local-name()))]"/>
		</fieldset>
	</xsl:template>
	
	<xsl:template match="*[matches(@visibleWhen, '.*!=\s?null')]">
		<!-- sub table of each content/page and its subsequent properties -->
		<table class="subtable subtablehighlight" style="margin-bottom:10px" border="3">
			<tr>
				<!-- Header with element name and the visible when clause -->
				<th class="column1 headerbg"><xsl:value-of select="local-name()"/></th>
				<th style="text-align:left" class="headerbg"><xsl:value-of select="./@visibleWhen"/></th>
			</tr>
			<!-- Show properties, injections and labels only if they are under the current visibleWhen -->
			<!-- <xsl:apply-templates select=".//property[generate-id(ancestor::*[matches(@visibleWhen, '.*!=\s?null')][1]) = generate-id(current())]"/> -->
			<xsl:apply-templates select=".//property[ancestor::*[matches(@visibleWhen, '.*!=\s?null')][1] = current()]"/>
			<!-- Pass current element to sub-template -->
			<xsl:call-template name="ChildVisibleWhen">
				<xsl:with-param name="parentNode" select="."/>
			</xsl:call-template>
		</table>

	</xsl:template>
	
	<xsl:template match="property">
		<tr>
			<td class="column1">Property:</td>
			<td><xsl:value-of select="./@name"/></td>
		</tr>
	</xsl:template>

	<xsl:template name="ChildVisibleWhen">
		<xsl:param name="parentNode"/>
		<tr>
			<td/>
			<!-- <td><xsl:apply-templates select="descendant::*[matches(@visibleWhen, '.*!=\s?null.*')][generate-id(ancestor::*[matches(@visibleWhen, '.*!=\s?null')][1]) = generate-id($parentNode)]"/></td> -->
			<td><xsl:apply-templates select="descendant::*[matches(@visibleWhen, '.*!=\s?null.*')][ancestor::*[matches(@visibleWhen, '.*!=\s?null')][1] = $parentNode]"/></td>
		</tr>
	</xsl:template>
	
</xsl:stylesheet>

I expect this:

I get this:

I can add a space or newline between any <content> and then it works fine. Since I can't guarantee the source will be formatted with a text node I've worked around it by using the generate-id function. From what I can tell I'm comparing single node sets so they should match regardless. I'm not seeing what is unique that comparing in these different scenarios should change the result.

line 62/63 and 83/84 are in here to make toggling between a working and not working template easier.

I've validated this happens in the saxon-he-12.5 w/xmlresolver-5.2.2.jar


Files

Please register to edit this issue

Also available in: Atom PDF