RE: [xsl] Abstracting XSLT to generate multiple forms for the same

Subject: RE: [xsl] Abstracting XSLT to generate multiple forms for the same
From: cknell@xxxxxxxxxx
Date: Thu, 02 Feb 2006 10:32:17 -0500
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" ?>
	  <full_name>Johnathon Wright</full_name>

This stylesheet will produce desired output #1:

<xsl:stylesheet version="1.0" xmlns:xsl="";>
  <xsl:output method="text" indent="yes" />
  <xsl:strip-space elements="*" />

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

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

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

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

  <xsl:template match="field_definition" />


If you change your input XML so:


you will get the alternate output:

full_name: Johnathon Wright

Charles Knell
cknell@xxxxxxxxxx - email

Current Thread