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 April 27th, 2015, 02:03 PM
Authorized User
 
Join Date: Apr 2008
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default Saxon Output current Template Name/Runtime Context

Is there a method to output the current template name/match in the output nodeset? I've looked through the Saxon Extensions/Functions and other library functions and I can't find this capability.

So if I have a <xsl:template match="X[Y]"> or <xsl:template name="FUBAR"> I'd want to put the "X[Y]" or "FUBAR" into the output XML. Is this possible?

I know if you turn on Timing Profiling (-TP) you get that information in the timing of each template match/name. But this is coming form the java code running on the processor, not the XSLT itself.
 
Old April 29th, 2015, 04:29 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The only way you would get the output you are asking for into the output nodeset is if you do it manually. I don't think there is a way of getting the current template selector though, so you will just have to do something like this:

Code:
<xsl:template match="X[Y]">
   <template match="X[Y]">
   ...
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old April 29th, 2015, 08:39 AM
Authorized User
 
Join Date: Apr 2008
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default

Yep, that's the hard coding that we fell back on for our needs. I was hoping there was a dynamic way with extension instructions/functions so we didn't have to update those if we made changes.. The saxon processor know that information, so I thought there might be a way, but I couldn't find in the documentation.

Thanks anyway.
 
Old April 29th, 2015, 09:08 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The interfaces are there in Saxon if you want to attempt it, but you'll have to grovel pretty deep. When you use -T (or -TP), Saxon does two things: firstly, at compile time it applies a CodeInjector which inserts extra code into the expression tree. Then at run-time, it supplies a TraceListener, which gets called at selected points by this injected code. You could exploit this to achieve the desired effect by writing a TraceListener which leaves the data you want "in a well known place", and then have an extension function which retrieves it from there.

But a simpler way, I think, would be to run an XSLT transformation on the stylesheet that generates xsl:message instructions at the start of each template rule.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Not In Current Context... shug BOOK: Beginning ASP.NET 4.5 : in C# and VB 1 May 24th, 2013 03:16 AM
The name 'ErrorMessage' does not exist in the current context ken evans BOOK: Beginning ASP.NET 4 : in C# and VB 9 November 3rd, 2010 06:48 AM
The name 'ErrorMessage' does not exist in the current context ken evans BOOK: Beginning ASP.NET 4 : in C# and VB 0 November 2nd, 2010 11:07 AM
The name 'partOneStep' does not exist in the current context pallone ASP.NET 3.5 Basics 11 March 4th, 2009 05:30 AM
The name 'txtOperande1' does not exist in the current context stevemcd999 BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 3 February 25th, 2009 11:58 PM





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