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 March 1st, 2006, 09:53 AM
Authorized User
 
Join Date: Jan 2006
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:

<?xml version="1.0" encoding="utf-8" ?>
<page>
  <fields>
    <noneditable>
      <language></language>
    </noneditable>
    <editable>
      <screens>
        <meta>
          <keywords formelement="textarea" maxlength="255"></keywords>
          <description formelement="textarea" maxlength="255"></description>
          <solution formelement="select"></solution>
          <sector formelement="select"></sector>
          <expertise formelement="select"></expertise>
        </meta>
        <front>
          <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>
        </front>
      </screens>
    </editable>
  </fields>
</page>

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.

 
Old March 1st, 2006, 10:03 AM
Authorized User
 
Join Date: Jan 2006
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old March 1st, 2006, 03:25 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





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





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