[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
At 2011-09-30 16:47 -0700, Mark wrote:
Answers below work equally well with XSLT 1.
select="../Stamp/Formats/@*[name(.)='minisheet']
... but that would be slower than:
select="../Stamp/Formats/@minisheet"
... typically one would write:
select="../Stamp/Formats/@*[name(.)=$thisAttrName]
More work would be necessary if the attributes were named with a namespace, since you wouldn't want to trigger on the prefix-qualified name.
document(concat(../../CatNumbers/@pofis-number,'.htm'))
The first ".." takes you from @souvenir-sheet to Formats. The second ".." takes you to Stamp. The rest are descendants.
In XPath, an attribute is not a child of its element, but the element is the attribute's parent.
I hope this helps.
. . . . . . . . . Ken
Re: [xsl] XPath questions: selecting from an attribute node axis and an attribute name variable
Subject: Re: [xsl] XPath questions: selecting from an attribute node axis and an attribute name variable From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 30 Sep 2011 19:54:17 -0400 |
At 2011-09-30 16:47 -0700, Mark wrote:
Hi, I am using XSLT 2.0. and have two questions I have been unable to resolve:
Answers below work equally well with XSLT 1.
(1) An attribute name variable:
Is it possible to write
<xsl:for-each select="../Stamp/Formats/@souvenir-sheet">
in such a way that @souvenir-sheet is replaced by a variable representing other attributes so that the same statement could be used to service a different specific <Formats> attribute? i.e, xsl:for-each select="../Stamp/Formats/@minisheet"> "Any" will not work, the name has to be specific.
select="../Stamp/Formats/@*[name(.)='minisheet']
... but that would be slower than:
select="../Stamp/Formats/@minisheet"
... typically one would write:
select="../Stamp/Formats/@*[name(.)=$thisAttrName]
More work would be necessary if the attributes were named with a namespace, since you wouldn't want to trigger on the prefix-qualified name.
(2) Selecting from the attribute axis:
From within the context provided by the execution of
xsl:for-each select="../Stamp/Formats/@souvenir-sheet">
in the <Stamp> element below , is it possible to select the element <CatNumber>'s attribute: pofis-number?
i.e.,
<xsl:variable name="file-name" select="concat([some XPath expression?]CatNumbers/@pofis-number, '.htm')"/>
XML fragment <Stamp> <CatNumbers scott-number="3040" scott-suffix="a" pofis-number="174"/> <Formats souvenir-sheet="174"/> </Stamp>
document(concat(../../CatNumbers/@pofis-number,'.htm'))
The first ".." takes you from @souvenir-sheet to Formats. The second ".." takes you to Stamp. The rest are descendants.
In XPath, an attribute is not a child of its element, but the element is the attribute's parent.
I hope this helps.
. . . . . . . . . Ken
-- Contact us for world-wide XML consulting and instructor-led training Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Google+ profile: https://plus.google.com/116832879756988317389/about Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
<- Previous | Index | Next -> |
---|---|---|
[xsl] XPath questions: selecting fr, Mark | Thread | Re: [xsl] XPath questions: selectin, Mark |
[xsl] XPath questions: selecting fr, Mark | Date | Re: [xsl] XPath questions: selectin, Mark |
Month |