Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 12th, 2012, 12:39 PM
Authorized User
 
Join Date: Sep 2012
Posts: 35
Thanks: 18
Thanked 0 Times in 0 Posts
Default Finding root of tree: the context item is undefined

Hi,

I am trying to create a transformation that will generate either XML and or CSV based on a bitwise operation. The data is provided via a POJO (to be passed as a xsl:param) but as I have no initial context here it would appear that what I want to do can't be done.
Code:
<?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:param name="target" as="xs:anyURI" required="no"/>
    <xsl:param name="types" as="xs:integer" required="no" select="3"/>
    <!-- This is the template called. (XsltTransformer.setInitialTemplate()) -->
    <xsl:template name="build">
        <!-- If the types parameter bitwise ands with 1 then create a CSV -->
        <xsl:if test="$types and 1 = 1">
            <xsl:apply-templates select="/" mode="CSV"/>
        </xsl:if>
        <!-- If the types parameter bitwise ands with 2 then create an XML -->
        <xsl:if test="$types and 2 = 2">
            <xsl:apply-templates select="/" mode="XML"/>
        </xsl:if>
    </xsl:template>
    <xsl:template match="/" mode="CSV">
        <xsl:comment>CSV BUilder Template</xsl:comment>
    </xsl:template>
    <xsl:template match="/" mode="XML">
        <xsl:comment>XML Builder Template</xsl:comment>
    </xsl:template>
</xsl:stylesheet>
Is anyone able to clarify this for me or even better if it is possible help me get passed this error?
--
William
 
Old December 12th, 2012, 03:03 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you want "/" to be just a dummy node, then you could do

Code:
<xsl:variable name="dummy"><doc/></xsl:variable>
and then

Code:
xsl:apply-templates select="$dummy"
But personally, I'd be more inclined to do it with named templates and xsl:call-template.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
WilliamYou (December 12th, 2012)
 
Old December 12th, 2012, 04:18 PM
Authorized User
 
Join Date: Sep 2012
Posts: 35
Thanks: 18
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by mhkay View Post
If you want "/" to be just a dummy node, then you could do

Code:
<xsl:variable name="dummy"><doc/></xsl:variable>
and then

Code:
xsl:apply-templates select="$dummy"
But personally, I'd be more inclined to do it with named templates and xsl:call-template.
Hello, and thank you for the reply. Using the dummy node approach works great, but what I thought would be a bitwise operation doesn't work the way I assumed but :
Code:
(floor($types  div 1) mod 2 = 1)
does.


Before posting I did try using call-template but gave up on it when Oxygen told me that mode was not supported on call-template or a name attributed template. Or is there something I've missed?

--
William

Last edited by WilliamYou; December 12th, 2012 at 04:24 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to access the document node if context item is an atomic value? apollo13 XSLT 4 August 2nd, 2010 08:27 AM
Unable to set context in web.xml or context.xml. dchicks Apache Tomcat 1 March 7th, 2008 07:59 AM
context-item returns...? maxtoroq XSLT 2 October 22nd, 2006 09:29 PM
How do i click the root menu item of skmMenu? dayib ASP.NET 1.x and 2.0 Application Design 0 September 12th, 2005 11:19 PM
Finding the first item EstherMStrom XSLT 9 September 30th, 2004 11:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.