Project

Profile

Help

Bug #1526

closed

Transform subelement of nested structure

Added by Todd Gochenour almost 12 years ago. Updated about 11 years ago.

Status:
Closed
Priority:
High
Assignee:
Sprint/Milestone:
Start date:
2012-05-07
Due date:
% Done:

100%

Estimated time:
Platforms:

Description

I have this XML:

<dataset oid="opalobj-12">

<menuitem oid="opalobj-12">

	<title>Applications</title>

	<img>/img/user1_monitor32.png</img>

	<type>submenu</type>

	<display_seq>1</display_seq>

	<id>apps</id>

	<item_title>Applications</item_title>

	<menuitem>

		<title>Labor Planning</title>

		<type>exec</type>

		<img>/img/worker32.png</img>

		<display_seq>2</display_seq>

		<id>apps_labor_management</id>

	</menuitem>

	<menuitem>

		<title>Mobile Apps</title>

		<type>exec</type>

		<img>/icon/32/laptop.png</img>

		<display_seq>3</display_seq>

		<id>apps_mobile</id>

	</menuitem>

	<menuitem>

		<title>Enterprise Architecture</title>

		<type>exec</type>

		<img>/icon/32/environment.png</img>

		<display_seq>4</display_seq>

		<id>apps_ear</id>

	</menuitem>

	<menuitem>

		<title>ERP Roadmap</title>

		<type>exec</type>

		<img>/icon/32/environment.png</img>

		<display_seq>5</display_seq>

		<id>apps_roadmap</id>

	</menuitem>

</menuitem>

<menuitem oid="opalobj-12">

	<title>Analytics</title>

	<img>/img/data_view32.png</img>

	<type>submenu</type>

	<display_seq>6</display_seq>

	<id>reports</id>

	<item_title>Analytics</item_title>

	<menuitem>

		<title>Query Tools</title>

		<type>exec</type>

		<img>/img/table_view32.png</img>

		<display_seq>7</display_seq>

		<id>reports_pivot</id>

	</menuitem>

</menuitem>

<menuitem oid="opalobj-12">

	<title>Tools</title>

	<img>/img/screwdriver32.png</img>

	<type>submenu</type>

	<display_seq>8</display_seq>

	<id>tools</id>

	<item_title>Tools</item_title>

	<menuitem>

		<title>Administration</title>

		<type>exec</type>

		<img>/img/wrench32.png</img>

		<display_seq>9</display_seq>

		<id>tools_admin</id>

	</menuitem>

	<menuitem>

		<title>Employee Search</title>

		<type>exec</type>

		<img>/img/wrench32.png</img>

		<display_seq>10</display_seq>

		<id>tools_employee_search</id>

	</menuitem>

</menuitem>

<menuitem>

	<title>Refresh</title>

	<img>/img/refresh32.png</img>

	<type>exec</type>

	<display_seq>11</display_seq>

	<id>refresh</id>

</menuitem>

<menuitem>

	<title>Logout</title>

	<img>/img/logout32.png</img>

	<type>exec</type>

	<display_seq>12</display_seq>

	<id>logout</id>

</menuitem>

I do an xpath selection in javascript:

var node = xml.selectSingleNode("//menuitem[id=reports]")

and then transform this node with an XSL template:

<xsl:stylesheet version = '1.0'	xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:output method="html"/>

<xsl:template match="menuitem"> 

<div class="startmenuitem">

and the current node that matches the single template in this XSL is node:

	<menuitem>

		<title>Query Tools</title>

		<type>exec</type>

		<img>/img/table_view32.png</img>

		<display_seq>7</display_seq>

		<id>reports_pivot</id>

	</menuitem>

It's as if the passed in node is treated as a #document node and the default template is firing:

<xsl:template match="/">

	<xsl:apply-templates />

</xsl:template>

If I change the condition on my template from 'menuitem' to '/', then the output of the XSL is what I am expecting. Shouldn't the template matching 'menuitem' actually match the root element passed into the transformation?

Actions #1

Updated by Philip Fearon almost 12 years ago

I understand how you're selecting a node in JavaScript, ~~but don't understand how you're applying a transform to it. Seeing a more complete sample would help me know what's going on a bit better-. The code you've posted is also being messed up by our forum site's rendering ~~ -can you submit the samples as files-?

Also, the JavaScript you've shown has a reference to a reports variable within the predicate, so I can't be sure what node is being selected.

-Conventionally, you would apply the transform to the document and use XSLT match patterns to select the node or nodes you want to transform, but I'm assuming this approach is down to having compatibility with an existing library?

[Edit] I've been corrected on this and now understand that it is quite common to initialise a transform on a node other than the document node - it's something I must confess I haven't done myself. No need to forward any more samples - a code inspection shows where the problem lies.

Actions #2

Updated by Philip Fearon almost 12 years ago

  • Priority changed from Low to High

Currently, the code for Saxon-CE's JavaScript API does not 'anticipate' any node types other than the document node being provided as the source. It appears non-document nodes are wrapped in a document node, any XSLT that exploits this wrapping behaviour would be unsafe because it will probably not work once this issue is fixed.

This is a bug in that an XSLT processor should be able to process any XML node type as the principal source - though in practice this would probably be an element node or a document node. The JavaScript API documentation for Saxon-CE reflects the current restriction to the document node, this should be updated once the fix is in place.

Actions #3

Updated by Todd Gochenour almost 12 years ago

OK, thanks for tracking this down, Phil. I'm glad to have found a common use case as yet anticipated. I look forward to testing the beta once this is fixed.

Actions #4

Updated by Philip Fearon almost 12 years ago

  • Status changed from New to Resolved
Actions #5

Updated by Philip Fearon almost 12 years ago

  • Sprint/Milestone set to Release 1.0
Actions #6

Updated by Philip Fearon almost 12 years ago

  • % Done changed from 0 to 100
Actions #7

Updated by O'Neil Delpratt about 11 years ago

  • Status changed from Resolved to Closed
  • Sprint/Milestone changed from Release 1.0 to Release 1.1
  • Found in version changed from Beta 0.2 to 1.0
  • Fixed in version set to 1.1

Bug fixed for Saxon-CE version 1.1 release

Please register to edit this issue

Also available in: Atom PDF