[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Pass XML document (*not* file path!) as parameter to X

Subject: Pass XML document (*not* file path!) as parameter to XSLT
From: "david bessire" <david_bessire@xxxxxxxxxxx>
Date: Thu, 17 May 2007 18:54:47 +0000
 Pass XML document (*not* file path!) as parameter to X
What's the proper way to pass an XML document as a parameter
to an XSLT, without writing that document to a file and
passing the filepath to the XSLT ?

In Java code, i create a org.dom4j.Document that describes
a user's roles and permissions; the structure looks like:

<pre>
<permsroles>
	<role>Contributor</role>
	<perm>View</perm>
</permsroles>
</pre>

These permissions are used to restrict menu items a user
is allowed to access.  The menu items are described by a
static xml document which looks like:

<pre>
<menuItems>
	<menuItem id="1" parentId="0">
		<ItemURL>URL1</ItemURL>
		<permsroles>
			<role>ADMIN</role>
			<role>Contributor</role>
		</permsroles>
	</menuItem>
	<menuItem id="11" parentId="1">
		<ItemURL>URL2</ItemURL>
	</menuItem>
	<menuItem id="2" parentId="0">
		<ItemURL>URL3</ItemURL>
		<permsroles>
			<perm>View</perm>
		</permsroles>
	</menuItem>
</menuItems>
</pre>

i want to use an XSLT to remove restricted menu items from the
static document by passing the <permsroles> document as a parameter
to the XSLT.  My transform looks like:

<pre>
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0">

	<xsl:param name="permsroles"/>
	<xsl:variable name="permsrolesLookup" select="document($permsroles)"/>

	<xsl:template match="/menuItems">
		<menuItems>
			<xsl:for-each select="menuItem">
				<xsl:choose >

<!-- select menuItem elements with no logical parent -->

<xsl:when test="count(../menuItem[@id = current()/@parentId]) = 0">

<!-- handle top-level menuItem elements and all logical children -->

						<xsl:call-template name="resolve-hierarchical-permissions">
							<xsl:with-param name="id">
								<xsl:value-of select="@id"/>
							</xsl:with-param>
						</xsl:call-template>
					</xsl:when>
				</xsl:choose>
			</xsl:for-each>
		</menuItems>
	</xsl:template>

	<xsl:template name="resolve-hierarchical-permissions" match="menuItem">
	<xsl:param name="id"/>
		<xsl:choose>

			<xsl:when test="not(permsroles)
				or permsroles/role/text() = $permsrolesLookup/permsroles/role/text()
				or permsroles/perm/text() = $permsrolesLookup/permsroles/perm/text()">

				<menuItem>
					<xsl:attribute name="id">
						<xsl:value-of select="@id"/>
					</xsl:attribute>
					<xsl:attribute name="parentId">
						<xsl:value-of select="@parentId"/>
					</xsl:attribute>

					<ItemURL>
						<xsl:value-of select="./ItemURL"/>
					</ItemURL>
				</menuItem>

<!-- recurse for all logical children -->

				<xsl:for-each select="/menuItems/menuItem[@parentId = $id]">
					<xsl:call-template name="resolve-hierarchical-permissions">
						<xsl:with-param name="id">
							<xsl:value-of select="@id"/>
						</xsl:with-param>
					</xsl:call-template>
				</xsl:for-each>
			</xsl:when>
		</xsl:choose>
	</xsl:template>

</xsl:stylesheet>
</pre>

When i do this from the command line using xalan-2_7_0 with <permsroles> defined
in a file, it works as expected. When i try to execute it in Java code using the
dynamically computed <permsroles> document, i get this error:


Can not load requested doc: no protocol: org.dom4j.tree.DefaultElement@3a52a34b [Element: <permsroles attributes: []/>]

i think the transform is trying to load the file from disk. How can i pass the dynamically
computed <permsroles> document to the XSLT as a parameter? i've tried removing 'document(...)'
but that also generates errors.


Do i need to include code to convert the Element into a NodeList?

Any help is appreciated.

Thanks,
david bessire

_________________________________________________________________
More photos, more messages, more storageget 2GB with Windows Live Hotmail. http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_2G_0507


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.