[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
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 |
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|