Re: [xsl] Trying to Extract a node with matching attribute value with xsltproc

Subject: Re: [xsl] Trying to Extract a node with matching attribute value with xsltproc
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 24 Mar 2024 10:40:44 -0000
To show you an example where the suggested XPath, with the input as
shown (edited to make it namespace well-formed) selects the wanted
element node, see the following XSLT fiddle
<https://martin-honnen.github.io/xslt3fiddle/?xslt=%3C%3Fxml+version%3D%221.0
%22+encoding%3D%22utf-8%22%3F%3E%0D%0A%3Cxsl%3Astylesheet+xmlns%3Axsl%3D%22ht
tp%3A%2F%2Fwww.w3.org%2F1999%2FXSL%2FTransform%22%0D%0A++version%3D%223.0%22%
0D%0A++xmlns%3Axs%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%22%3E%0D%0A
%0D%0A++%3Cxsl%3Atemplate+match%3D%22%2F%22+name%3D%22xsl%3Ainitial-template%
22%3E%0D%0A++++%3Cxsl%3Acopy-of+select%3D%22%2F%2FSetting%5B%40Name+%3D+%27Th
eOneIWant%27%5D%22+copy-namespaces%3D%22no%22%2F%3E%0D%0A++%3C%2Fxsl%3Atempla
te%3E%0D%0A++%0D%0A%3C%2Fxsl%3Astylesheet%3E%0D%0A&input=%3Cxsd%3AConf+xmlns%
3Axsd%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%22%3E%0D%0A%0D%0A+++%3C
SettingHandler%3E%0D%0A+++.%0D%0A+++.%0D%0A+++%3C%2FSettingHandler%3E%0D%0A%0
D%0A+++%3CSettingHandler%3E%0D%0A+++.%0D%0A+++.%0D%0A+++%3C%2FSettingHandler%
3E%0D%0A%0D%0A+++%3CSetting+Name%3D%22AAA%22%3E%0D%0A+++.%0D%0A+++.%0D%0A+++%
3C%2FSetting%3E%0D%0A%0D%0A+++%3CSetting+Name%3D%22TheOneIWant%22+Type%3D%22h
tf%3Amap%22%3E%0D%0A++++++%3CSetting+Name%3D%22requiresignedassertion%22+Type
%3D%22xsd%3Aboolean%22%3Efalse%3C%2FSetting%3E%0D%0A++++++%3CSetting+Name%3D%
22succinctid%22+Type%3D%22xsd%3Astring%22%3E2KYi3gZ7THiZU0Hbft%2FmYgio0PE%3D%
3C%2FSetting%3E%0D%0A+++.%0D%0A+++.%0D%0A+++%3C%2FSetting%3E%0D%0A%0D%0A+++%3
CSetting+Name%3D%22BBB%22%3E%0D%0A+++.%0D%0A+++.%0D%0A+++%3C%2FSetting%3E%0D%
0A%0D%0A%3C%2Fxsd%3AConf%3E%0D%0A&input-type=XML>.
As commented by others, if you didn't show all namespace declarations in
the real input sample, all suggested XPath expressions might fail to
select something.

Am 24.03.2024 um 01:35 schrieb ohaya ohaya@xxxxxxxxx:
> I tried the XSL that Liam suggested, but it isn't finding anything
> :(....B  Below is the xsltproc run with -v:
>
> -bash-4.4$ xsltproc -v mulberry.xsl configfile.xml
> creating dictionary for stylesheet
> reusing dictionary from mulberry.xsl for stylesheet
> xsltParseStylesheetProcess : found stylesheet
> xsltPreprocessStylesheet: removing ignorable blank node
> xsltCompilePattern : parsing '/'
> xsltCompilePattern : parsed /, default priority 0.500000
> added pattern : '/' priority 0.500000
> parsed 1 templates
> Resolving attribute sets references
> Creating sub-dictionary from stylesheet for transformation
> Registered 0 modules
> reusing transformation dict for output
> Registering global variables
> Registering global variables from mulberry.xsl
> xsltProcessOneNode: applying template '/' for /
> xsltValueOf: select //Setting[@Name = 'TheOneIWant']
> xsltValueOf: result ''
> freeing transformation dictionary
> freeing dictionary from stylesheet
>
>
>
> Here's snippet of the XML file which should have matched:
>
> B B B B B B B B B B B  <Setting Name="TheOneIWant" Type="htf:map">
> B B B B B B B B B B B B B  <Setting Name="requiresignedassertion"
> Type="xsd:boolean">false</Setting>
> B B B B B B B B B B B B B  <Setting Name="succinctid"
> Type="xsd:string">2KYi3gZ7THiZU0Hbft/mYgio0PE=</Setting>
>
> .
> .
> B B B B B B B B B  </Setting>
> .
> .
>
> Also, I think that I may not have been clear about what I want as the
> output of running the XSLT...
>
> If the XSLT was successful, I want the output to be the ENTIRE
> matching node, including all the contents of the node, i.e.:
>
> B B B B B B B B B B B  <Setting Name="TheOneIWant" Type="htf:map">
> B B B B B B B B B B B B B  <Setting Name="requiresignedassertion"
> Type="xsd:boolean">false</Setting>
> B B B B B B B B B B B B B  <Setting Name="succinctid"
> Type="xsd:string">2KYi3gZ7THiZU0Hbft/mYgio0PE=</Setting>
>
> .
> .
> </Setting>
>
> That's why, in my original post, I thought I had to include use of the
> identity transformation.
>
>
> My apologies if I wasn't clear about that.
>
> Thanks,
> Jim
>
>
>
>
>
> On Saturday, March 23, 2024 at 02:09:01 PM EDT, BR Chrisman
> brchrisman@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
>
> Might needB to use <xsl:output method="text"/> as well.
>
> On Fri, Mar 22, 2024 at 7:19b/PM Liam R. E. Quin liam@xxxxxxxxxxxxxxxx
> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
>     On Sat, 2024-03-23 at 01:55 +0000, ohaya ohaya@xxxxxxxxx wrote:
>     [...]
>
>     I think what you want is simply XPath here.
>
>     But with XSLT you could use,
>
>     <xsl:stylesheet version="1.0"
>     xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
>
>     B  <xsl:template match="/">
>     B  B  <xsl:value-of select="//Setting[@Name = 'TheOneIWant']" />
>     B  </xsl:template>
>     </xsl:stylesheet>
>
>     The xsl:value-of "instruction" evalueates its argument and
>     converts the
>     result to a string (actually a "text node").
>
>     The contents of the "select" attribute is an XPath expression.
>
>     liam
>
>
>     --
>     Liam Quin, https://www.delightfulcomputing.com/
>     Available for XML/Document/Information Architecture/XSLT/
>     XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
>     Barefoot Web-slave, antique illustrations: http://www.fromoldbooks.org
>
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/3475705>
> (by email)
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/582271>
> (by email <>)

Current Thread