{"id":46,"date":"2004-11-16T02:09:03","date_gmt":"2004-11-16T02:09:03","guid":{"rendered":"http:\/\/gaisan.com\/wordp\/?p=46"},"modified":"2004-11-16T02:09:03","modified_gmt":"2004-11-16T02:09:03","slug":"escaping-entities-using-xslt","status":"publish","type":"post","link":"http:\/\/gaisan.com\/blogs\/?p=46","title":{"rendered":"Escaping entities using XSLT"},"content":{"rendered":"<p>While writing the last post I didn&#8217;t fancy the idea of hand escaping the HTML entities into the MSN XML output. So I cheated using a funky little piece of XSLT that I cooked up earlier tonight. It&#8217;s listed below&#8230;<br \/>\n<code><br \/>\n<?xml version=\"1.0\" encoding=\"UTF-16\"?>&lt;xsl:stylesheet version=\"1.0\"&gt;<br \/>\n&lt;xsl:output method=\"xml\" indent=\"yes\" omit-xml-declaration=\"no\" doctype-<br \/>\nsystem=\"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\" doctype-public=<br \/>\n\"-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN\"&gt;    &lt;\/xsl:output&gt;<br \/>\n&lt;xsl:template match=\"\/\"&gt;<br \/>\n&lt;xsl:call-template name=\"escapexml\"&gt;<br \/>\n&lt;xsl:with-param name=\"block\" select=\".\"&gt;  &lt;\/xsl:with-param&gt;<br \/>\n&lt;\/xsl:call-template&gt;<br \/>\n&lt;\/xsl:template&gt;<br \/>\n&lt;xsl:template name=\"escapexml\"&gt;<br \/>\n&lt;xsl:param name=\"block\"&gt;        &lt;\/xsl:param&gt;<br \/>\n&lt;xsl:for-each select=\"$block\/*|$block\/text()\"&gt;<br \/>\n&lt;xsl:choose&gt;<br \/>\n&lt;xsl:when test=\"self::text()\"&gt;<br \/>\n&lt;xsl:value-of select=\".\"&gt;     &lt;\/xsl:value-of&gt;<br \/>\n&lt;\/xsl:when&gt;<br \/>\n&lt;xsl:otherwise&gt;<br \/>\n&lt;xsl:text&gt;    &amp;lt;&lt;\/xsl:text&gt;<br \/>\n&lt;xsl:value-of select=\"name(.)\"&gt;       &lt;\/xsl:value-of&gt;<br \/>\n&lt;xsl:for-each select=\"@*\"&gt;<br \/>\n&lt;xsl:value-of select=\"concat(' ', name())\"&gt;<br \/>\n&lt;\/xsl:value-of&gt;<br \/>\n&lt;xsl:text&gt;       =\"&lt;\/xsl:text&gt;<br \/>\n&lt;xsl:value-of select=\".\"&gt;        &lt;\/xsl:value-of&gt;<br \/>\n&lt;xsl:text&gt;       \"&lt;\/xsl:text&gt;<br \/>\n&lt;\/xsl:for-each&gt;<br \/>\n&lt;xsl:text&gt;    &amp;gt;    &lt;\/xsl:text&gt;<br \/>\n&lt;xsl:choose&gt;<br \/>\n&lt;xsl:when test=\"*\"&gt;<br \/>\n&lt;xsl:call-template name=\"escapexml\"&gt;<br \/>\n&lt;xsl:with-param name=\"block\" select=\".\"&gt<br \/>\n;       &lt;\/xsl:with-param&gt;<br \/>\n&lt;\/xsl:call-template&gt;<br \/>\n&lt;\/xsl:when&gt;<br \/>\n&lt;xsl:otherwise&gt;<br \/>\n&lt;xsl:value-of select=\".\"&gt;   &lt;\/xsl:value-of&gt;<br \/>\n&lt;\/xsl:otherwise&gt;<br \/>\n&lt;\/xsl:choose&gt;<br \/>\n&lt;xsl:text&gt;    &amp;lt;\/&lt;\/xsl:text&gt;<br \/>\n&lt;xsl:value-of select=\"name(.)\"&gt;       &lt;\/xsl:value-of&gt;<br \/>\n&lt;xsl:text&gt;    &amp;gt;    &lt;\/xsl:text&gt;<br \/>\n&lt;\/xsl:otherwise&gt;<br \/>\n&lt;\/xsl:choose&gt;<br \/>\n&lt;\/xsl:for-each&gt;<br \/>\n&lt;\/xsl:template&gt;<br \/>\n&lt;\/xsl:stylesheet&gt;<br \/>\n<\/code><br \/>\nI&#8217;ll produce a tidier more <i>beautifying<\/i> version when I get the time but it&#8217;s OK for a first attempt and I know of at least one person who&#8217;s asked me to do something similiar in the past. And on that note.. it could be time to hit the hay \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While writing the last post I didn&#8217;t fancy the idea of hand escaping the HTML entities into the MSN XML output. So I cheated using a funky little piece of XSLT that I cooked up earlier tonight. It&#8217;s listed below&#8230; &lt;xsl:stylesheet version=&#8221;1.0&#8243;&gt; &lt;xsl:output method=&#8221;xml&#8221; indent=&#8221;yes&#8221; omit-xml-declaration=&#8221;no&#8221; doctype- system=&#8221;http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd&#8221; doctype-public= &#8220;-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN&#8221;&gt; &lt;\/xsl:output&gt; &lt;xsl:template [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"_links":{"self":[{"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/46"}],"collection":[{"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=46"}],"version-history":[{"count":1,"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/46\/revisions"}],"predecessor-version":[{"id":531,"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/46\/revisions\/531"}],"wp:attachment":[{"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=46"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=46"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}