Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 1st, 2006, 09:53 AM
Authorized User
Join Date: Jan 2006
Location: , , .
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamically Finding Elements in XSL

Related to my previous post (http://p2p.wrox.com/topic.asp?TOPIC_ID=40752), I have a document filled with elements that I'm turning into an HTML form. I have:

1. An XML document describing each of the form fields that should appear on the page (these are dynamic based on what the user is doing, so I don't know the names of the elements).
2. A block I'm adding to the XML at run-time that provides existing content to populate the form elements with.
3. As an additional point of confusion, there can be more than one piece of content in #2; in these cases, I want to show one copy of the relevant form element from #1 for each piece of content.


<?xml version="1.0" encoding="utf-8" ?>
          <keywords formelement="textarea" maxlength="255"></keywords>
          <description formelement="textarea" maxlength="255"></description>
          <solution formelement="select"></solution>
          <sector formelement="select"></sector>
          <expertise formelement="select"></expertise>
          <title formelement="text" validation="notempty" errormessage="Please provide a title" sortable="alpha" maxlength="255"></title>
          <strapline formelement="text" maxlength="255"></strapline>
          <headerimage formelement="library" library="headerimages"></headerimage>
          <tagline formelement="library" library="taglines"></tagline>
          <maincontent formelement="richtext" allowmultiple="true" maincontent="true"></maincontent>
          <focusareas formelement="noidea" allowmultiple="true"></focusareas>

I'm inserting a block in <page> called <contents>. For every item that has content, I'm inserting a child into <contents> named the same as the tag inside screens (e.g., /page/contents/maincontent) and then inserting each piece of content as an <item> child of that block.

What I've read suggests there's no dynamic XPath in XSLT 1.0. Given that, is there some way for me to get at the proper contents during a transformation?

Apologies for the confusing mess of a question. Let me know how best to clarify.

Reply With Quote
  #2 (permalink)  
Old March 1st, 2006, 10:03 AM
Authorized User
Join Date: Jan 2006
Location: , , .
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts

Given I'm working in C#, http://msdn.microsoft.com/library/de...etFunction.asp looks promising.

Reply With Quote
  #3 (permalink)  
Old March 1st, 2006, 03:25 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

I don't think you need dynamic XPath to do this. The only things that are variable (or data-driven) are element names, and you can handle dynamic element names easily in XPath (and XSLT), using constructs such as select="*[name()=$param]" and <xsl:element name="{$param]"/>. You would only need dynamic XPath if you didn't know until run-time what operators to use, e.g. whether to do "+" or "-", or "and" or "or".

(Having said that, there are plenty of applications that make effective use of extensions like saxon:evaluate() that provide dynamic XPath evaluation)

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding nested elements XSLT 1? Budbertzerofluff XSLT 2 November 15th, 2008 02:45 PM
finding max string length if more than 2 elements srini XSLT 4 April 4th, 2006 01:08 PM
adding option elements dynamically to a select richard.york Javascript 4 December 5th, 2003 04:57 AM
Dynamically expanding and collapsing elements richard.york Javascript 3 November 26th, 2003 09:17 PM
Dynamically Named form elements conundrum Javascript How-To 4 October 1st, 2003 04:04 AM

All times are GMT -4. The time now is 10:09 AM.

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