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

Trying to Extract a node with matching attribute value

Subject: Trying to Extract a node with matching attribute value with xsltproc
From: "ohaya ohaya@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 23 Mar 2024 01:54:17 -0000
 Trying to Extract a node with matching attribute value
Hi,
I am trying to use xslt and xsltproc (on Redhat) to extract one of the nodes
from a versy large XML file.
The XML file is structured similar to the following:
<xsd:Conf>


B B  <SettingHandler....
B B  .
B B  .
B B  </SettingHandler>

B B  <SettingHandler....
B B  .
B B  .
B B  </SettingHandler>

B B  <Setting Name="AAA"....
B B  .
B B  .
B B  </Setting>

B B  <Setting Name="TheOneIWant"....
B B  .
B B  .
B B  </Setting>

B B  <Setting Name="BBB"....
B B  .
B B  .
B B  </Setting>

</xsd:Conf>




B B  <SettingHandler....
B B  .
B B  .
B B  </SettingHandler>

B B  <SettingHandler....
B B  .
B B  .
B B  </SettingHandler>

B B  <Setting Name="AAA"....
B B  .
B B  .
B B  </Setting>

B B  <Setting Name="TheOneIWant"....
B B  .
B B  .
B B  </Setting>

B B  <Setting Name="BBB"....
B B  .
B B  .
B B  </Setting>

</xsd:Conf>

I want to just extract the <Setting> node that has the 'Name' attribute with
value 'TheOneIWant'.
I've been trying an XSLT as follows:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">



B B  <!-- IdentityTransform -->
B B  <xsl:template match="/ | @* | node()">
B B B B B B B B  <xsl:copy>
B B B B B B B B B B B B B B  <xsl:apply-templates select="@* | node()" />
B B B B B B B B  </xsl:copy>
B B  </xsl:template>

<!-- Copy only the node named 'Setting' with attribute 'Name'='TheOneIWant'
-->
<xsl:template match="Setting">
B B  <xsl:if test="@Name = 'TheOneIWant'">
B B B B B B  <xsl:apply-templates/>
B B  </xsl:if>
</xsl:template>

</xsl:stylesheet>

But, instead of extract just that node with "Name" of "TheOneIWant", it looks
like it is basically copying the entire original file by executing the
identity transform on every node :(...
Can someone explain how I can modify the xslt so that it just outputs the one
node that matches the attribute?
Thanks in advance!
Jim




|  | Virus-free.www.avast.com |

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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

Buy Stylus Studio Now

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