Subject: [xsl] 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 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Seek an XPath expression , Michael Kay michaelk | Thread | Re: [xsl] Trying to Extract a node , Liam R. E. Quin liam |
Re: [xsl] Seek an XPath expression , Michael Kay mike@xxx | Date | Re: [xsl] Trying to Extract a node , Liam R. E. Quin liam |
Month |