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" ?> <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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Abstracting XSLT to gener, David Carlisle | Thread | [xsl] bad match expression, Terence Kearns |
Re: [xsl] Abstracting XSLT to gener, David Carlisle | Date | Re: [xsl] Element selection based o, Wendell Piez |
Month |