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

RE: Abstracting XSLT to generate multiple forms for th

Subject: RE: Abstracting XSLT to generate multiple forms for the same
From: cknell@xxxxxxxxxx
Date: Thu, 02 Feb 2006 10:32:17 -0500
multiple doc output xslt
I suspect you mis-typed the expected output. Based on the example XML, I surmise that the output you wanted is:

username: eattabasco

and when you change to full_name, the output you expect is:

full_name: Johnathon Wright

as you stated.

This really isn't very complicated. I took your XML and added an enclosing element to make it well-formed (note; I have studiously excluded the term "root" in describing this element because it seems that term is defined differently in XML and XPath and I don't want to wander into that swamp again).

<?xml version="1.0" encoding="UTF-8" ?>
<doc>
	<field_definition>
	  <name>username</name>
	  <type>text</type>
	</field_definition>
	<data>
	  <username>eattabasco</username>
	  <full_name>Johnathon Wright</full_name>
	</data>
</doc>

This stylesheet will produce desired output #1:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text" indent="yes" />
  <xsl:strip-space elements="*" />

  <xsl:template match="/">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:variable name="target" select="/doc/field_definition/name" />

  <xsl:template match="doc">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="data">
    <xsl:value-of select="$target" />:<xsl:value-of select="child::node()[local-name()= $target]" />
  </xsl:template>

  <xsl:template match="field_definition" />

</xsl:stylesheet>

If you change your input XML so:

<name>full_name</name>

you will get the alternate output:

full_name: Johnathon Wright


-- 
Charles Knell
cknell@xxxxxxxxxx - email

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

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-2007 All Rights Reserved.