{ "name/string" "an XML name or string representing the name" }
{ "matching-tag" tag } }
{ $description "Finds the first tag with matching name which is the direct child of the given tag." }
-{ $see-also deep-tags-named deep-tag-named tags-named } ;
+{ $see-also deep-tags-named deep-tag-named tag-named-with-attr tags-named } ;
+
+HELP: tag-named-with-attr
+{ $values { "tag" "an XML tag or document" }
+ { "tag-name" "an XML name or string representing the name" }
+ { "attr-value" "a string representing the attribute value" }
+ { "attr-name" "a string representing the attribute name" }
+ { "matching-tag" tag } }
+{ $description "Finds the first tag with matching name with the corresponding attribute name and value which is the direct child of the given tag." }
+{ $see-also tag-named } ;
HELP: tags-named
{ $values { "tag" "an XML tag or document" }
! Copyright (C) 2005, 2009 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
-USING: xml xml.traversal tools.test xml.data sequences arrays ;
+USING: xml xml.traversal tools.test xml.data sequences arrays kernel ;
IN: xml.traversal.tests
[ "bar" ] [ "<foo>bar</foo>" string>xml children>string ] unit-test
[ { "blah" } ] [ "<foo><bar attr='blah'/></foo>" string>xml "blah" "attr" tags-with-attr [ "attr" attr ] map ] unit-test
[ { "blah" } ] [ "bar" { { "attr" "blah" } } f <tag> 1array "blah" "attr" tags-with-attr [ "attr" attr ] map ] unit-test
+
+[ { "http://hub.example.com" "http://alt.example.com" } ] [ "<head><link rel='alternate' href='http://alt.example.com'/><link rel='hub' href='http://hub.example.com'/></head>" string>xml-chunk "head" tag-named [ "link" "hub" "rel" tag-named-with-attr ] [ "link" "alternate" "rel" tag-named-with-attr ] bi [ "href" attr ] bi@ 2array ] unit-test
: tag-with-attr ( tag attr-value attr-name -- matching-tag )
assure-name '[ _ _ tag-with-attr? ] find nip ;
+: tag-named-with-attr ( tag tag-name attr-value attr-name -- matching-tag )
+ [ tags-named ] 2dip '[ _ _ tag-with-attr? ] find nip ;
+
: tags-with-attr ( tag attr-value attr-name -- tags-seq )
assure-name '[ _ _ tag-with-attr? ] { } filter-as ;