{"id":20412,"date":"2021-12-17T09:51:46","date_gmt":"2021-12-17T08:51:46","guid":{"rendered":"https:\/\/www.zylstra.org\/blog\/?p=20412"},"modified":"2021-12-17T10:10:50","modified_gmt":"2021-12-17T09:10:50","slug":"20412","status":"publish","type":"post","link":"https:\/\/www.zylstra.org\/blog\/2021\/12\/20412\/","title":{"rendered":""},"content":{"rendered":"<p>TIL: In an xml style sheet, an xslt file, testing for the existence of an attribute is not the same as testing whether an attribute has content.<\/p>\n<p>I have a machine readable file (OPML) with lines such as <\/p>\n<p><code>&lt;outline type=&quot;book&quot; text=&quot;title by author&quot; name=&quot;book title&quot; author=&quot;author name&quot; url=&quot;&quot; comment=&quot;some remarks&quot; authorurl=&quot;&quot; inLanguage=&quot;en&quot; \/&gt;<\/code>\t<\/p>\n<p>I want to show that file in a browser for people to see, and I want to test for the attribute url in that line so that I can mark up the text with a web link in the human readable version.<\/p>\n<p>What I first used to test for the presence of a link was:<\/p>\n<p><code>&lt;xsl:when test=&quot;@url&quot;&gt;<\/code><\/p>\n<p>I assumed this would test for the actual presence of a value for attribute &#8216;url&#8217;. But that is not correct. The statement actually tests whether the attribute &#8216;url&#8217; is present in the line of machine readable code.<\/p>\n<p>To test if the url attribute also has content in it, e.g. url=&#8221;https:\/\/weblink.tld\/page&#8221; and not url=&#8221;&#8221; I need to check that the field is not empty:<\/p>\n<p><code>&lt;xsl:when test=&quot;@url!=&#039;&#039;&quot;&gt;<\/code><\/p>\n<p>I experimentally create OPML lists of books I read (see <a href=\"https:\/\/www.zylstra.org\/blog\/2021\/04\/federated-bookshelves-revisited\/\">why<\/a> and <a href=\"https:\/\/www.zylstra.org\/blog\/booklist-opml-data-structure\/\">how<\/a>). For instance I have a &#8216;fiction 2021&#8217; list. OPML files are meant to be read by machines, but I use the same file to make a human readable version. In the human readable version I want to link to a book and to an author if I have a direct link to a page about the book (by the publisher or author) and a link to the author&#8217;s website. I test for non-empty url attributes so I know when to construct a link in the human readable output. You can <a href=\"https:\/\/zylstra.org\/opml\/books\/test.xsl\">download the XSLT I use<\/a> to do that and of course the <a href=\"https:\/\/zylstra.org\/opml\/books\/fiction2021.opml\">OPML file that lists the fiction books for 2021<\/a> (also see right hand side column, in the feeds section).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>TIL: In an xml style sheet (xslt), testing for the existence of an attribute is not the same as testing whether an attribute has content.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"webmentions_disabled_pings":false,"webmentions_disabled":false,"footnotes":""},"categories":[487,86,89],"tags":[425,891,643,1964],"class_list":["post-20412","post","type-post","status-publish","format-standard","category-timeline","category-metablogging","category-technology","tag-books","tag-federation","tag-opml","tag-xml","no-title","h-entry","hentry"],"archive_meta":{"categories":["Day to Day","metablogging","technology"],"tags":["books","federation","opml","xml"],"page_categories":[],"format":null,"kind":null,"ref":null},"_links":{"self":[{"href":"https:\/\/www.zylstra.org\/blog\/wp-json\/wp\/v2\/posts\/20412","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zylstra.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zylstra.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zylstra.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zylstra.org\/blog\/wp-json\/wp\/v2\/comments?post=20412"}],"version-history":[{"count":9,"href":"https:\/\/www.zylstra.org\/blog\/wp-json\/wp\/v2\/posts\/20412\/revisions"}],"predecessor-version":[{"id":20421,"href":"https:\/\/www.zylstra.org\/blog\/wp-json\/wp\/v2\/posts\/20412\/revisions\/20421"}],"wp:attachment":[{"href":"https:\/\/www.zylstra.org\/blog\/wp-json\/wp\/v2\/media?parent=20412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zylstra.org\/blog\/wp-json\/wp\/v2\/categories?post=20412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zylstra.org\/blog\/wp-json\/wp\/v2\/tags?post=20412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}