{"id":225523,"date":"2024-03-06T08:00:00","date_gmt":"2024-03-06T08:00:00","guid":{"rendered":"https:\/\/www.weixiaoduo.com\/plugins\/tenandtwo-xslt-processor\/"},"modified":"2024-08-27T23:20:00","modified_gmt":"2024-08-27T23:20:00","slug":"tenandtwo-xslt-processor","status":"publish","type":"post","link":"https:\/\/www.weixiaoduo.com\/plugins\/tenandtwo-xslt-processor\/","title":{"rendered":"Ten&#038;Two XSLT Processor"},"content":{"rendered":"<p>The Ten&Two XSLT Processor plugin brings the power of PHP\u2019s XSL extension to WordPress.  Once enabled, the plugin creates three (3) shortcodes \u2013 <code>[xslt_transform_xml\/]<\/code>, <code>[xslt_select_xml\/]<\/code>, and <code>[xslt_select_csv\/]<\/code> \u2013 which can be used separately or in tandem to enrich your site with content from XML and CSV sources.  The plugin also enables two (2) custom post types \u2013 <code>XSL Stylesheets<\/code> and <code>XML Documents<\/code> \u2013 for managing and validating sources within WP Admin.<\/p>\n<p>Detailed documentation and sample code can be found at https:\/\/plugins.tenandtwo.com\/<\/p>\n<h3>Custom Post Types<\/h3>\n<p>The XSLT Processor plugin provides two (2) custom post types for managing sources within WordPress \u2013 <code>XSL Stylesheets<\/code> and <code>XML Documents<\/code>.  Both types include basic syntax validation.  XML Documents can be validated further using DTD, XSD, or RNG.  Both types are enabled in Settings > XSLT Processor Settings > Activate Content Types.<\/p>\n<h3>Shortcode : [xslt_transform_xml\/]<\/h3>\n<pre><code>[xslt_transform_xml\/] is the plugin's primary function.  This shortcode processes XML data using an XSL stylesheet, and then outputs the result as HTML, more XML, or as simple TEXT.\n<\/code><\/pre>\n<ul>\n<li><code>[xslt_transform_xml xsl=\"{file|url|id|slug}\" xml=\"{file|url|id|slug}\" \/]<\/code><\/li>\n<li><code>[xslt_transform_xml xsl=\"{file|url|id|slug}\"]<DATA>...<\/DATA>[\/xslt_transform_xml]<\/code><\/li>\n<\/ul>\n<p>If either the <code>xsl<\/code> or <code>xml<\/code> parameter is left unspecified, defaults are used.  The default XML value is <code><NODATA\/><\/code>.  The default XSL stylesheet prints all of the incoming data as HTML.  If extra attributes are specified in the shortcode \u2013 eg, <code>mykey=\"myval\"<\/code> \u2013 those keys\/values are passed along as parameters to the stylesheet \u2013 <code><xsl:param name=\"mykey\"\/><\/code>.<\/p>\n<h3>Shortcode : [xslt_select_xml\/]<\/h3>\n<pre><code>[xslt_select_xml\/] is a helper function.  It reads XML and returns a selection of the data, based on a supplied XPath expression.  There are two (2) options for specifying the XPath.  First, using the `select` attribute or, second, using the body of the shortcode.  Complex select statements with quotes, square brackets or other special syntax, should use the second pattern :\n<\/code><\/pre>\n<ul>\n<li><code>[xslt_select_xml xml=\"{file|url|id|slug}\" select=\"{XPath}\" \/]<\/code><\/li>\n<li><code>[xslt_select_xml xml=\"{file|url|id|slug}\"]{XPath}[\/xslt_select_xml]<\/code><\/li>\n<\/ul>\n<p>If the XPath select parameter is left unspecified, the default <code>\/<\/code> is used, which returns the entire document.  The default output is <code>format=\"xml\"<\/code>.  If <code>format=\"json\"<\/code> is specified, the result is encoded as a JSON string.<\/p>\n<h3>Shortcode : [xslt_select_csv\/]<\/h3>\n<pre><code>[xslt_select_csv\/] is a helper function for converting CSV file data to XML.  The result can be output directly as an HTML `<table>`, or the result can be passed to `[xslt_transform_xml\/]` for further processing.\n<\/code><\/pre>\n<ul>\n<li><code>[xslt_select_csv csv=\"{file|url}\" \/]<\/code><\/li>\n<li><code>[xslt_select_csv]{csv,data}[\/xslt_select_csv]<\/code><\/li>\n<\/ul>\n<p>Three (3) parameters \u2013 <code>separator<\/code>, <code>enclosure<\/code>, <code>escape<\/code> \u2013 control reading the input.  See PHP\u2019s <code>fgetcsv()<\/code> function for details.<\/p>\n<ul>\n<li><code>[xslt_select_csv separator=\",\" enclosure=\"\"\" escape=\"\\\" \/]<\/code><\/li>\n<\/ul>\n<p>Two (2) parameters \u2013 <code>key_row<\/code>, <code>col<\/code> \u2013 control writing columns to the output.  The <code>key_row<\/code> attribute is optional, but allows labels from that row to be used in <code>col<\/code> and <code>key_col<\/code>.<\/p>\n<ul>\n<li><code>[xslt_select_csv key_row=\"{num}\" col=\"{num|letter|label}+\" \/]<\/code><\/li>\n<\/ul>\n<p>Three (3) parameters \u2013 <code>row<\/code>, <code>key_col<\/code>, <code>key<\/code> \u2013 control writing rows to the output.<\/p>\n<ul>\n<li><code>[xslt_select_csv row=\"{num}+\" \/]<\/code><\/li>\n<li><code>[xslt_select_csv key_col=\"{num|letter|label}\" key=\"{val}+\" \/]<\/code><\/li>\n<\/ul>\n<h3>Nested Shortcodes<\/h3>\n<p>Combine <code>[xslt_transform_xml]<\/code> with <code>[xslt_select_xml]<\/code> :<\/p>\n<ul>\n<li><code>[xslt_transform_xml][xslt_select_xml\/][\/xslt_transform_xml]<\/code><\/li>\n<\/ul>\n<p>Combine <code>[xslt_transform_xml]<\/code> with <code>[xslt_select_csv]<\/code> :<\/p>\n<ul>\n<li><code>[xslt_transform_xml][xslt_select_csv\/][\/xslt_transform_xml]<\/code><\/li>\n<\/ul>\n<p>Combine <code>[xslt_transform_xml]<\/code> with itself using <code>[\/xslt_transform_alias]<\/code> (WP does not support nested shortcodes with identical names) :<\/p>\n<ul>\n<li><code>[xslt_transform_alias][xslt_transform_xml\/][\/xslt_transform_alias]<\/code><\/li>\n<\/ul>\n<p>Combine multiple shortcodes\/sources to create a single <code>XML Document<\/code> (see Custom Post Types above) :<\/p>\n<ul>\n<li><code><DATA><PART1>[xslt_select_xml xml=\"f1.xml\" \/]<\/PART1><PART2>[xslt_select_xml xml=\"f2.xml\" \/]<\/PART2><\/DATA><\/code><\/li>\n<\/ul>\n<h3>Cache Parameters<\/h3>\n<p>When a shortcode specifies a remote file \u2013 <code>xml=\"{url}\"<\/code> or <code>csv=\"{url}\"<\/code> \u2013 that source is cached locally using WP Transients. The default cache duration is set in the XSLT Processor Settings.  To override the default, add <code>cache=\"{minutes}\"<\/code> to the shortcode.<\/p>\n<ul>\n<li><code>[xslt_transform_xml xml=\"{url}\" cache=\"{minutes}\" \/]<\/code><\/li>\n<li><code>[xslt_select_xml xml=\"{url}\" cache=\"{minutes}\" \/]<\/code><\/li>\n<li><code>[xslt_select_csv csv=\"{url}\" cache=\"{minutes}\" \/]<\/code><\/li>\n<\/ul>\n<h3>Namespace Parameters<\/h3>\n<p>Within <code>[xslt_select_xml\/]<\/code> the plugin provides two (2) methods for handling XML containing namespaces.  The first is to add <code>strip-namespaces<\/code> to the shortcode.  The second method is to add the needed prefixes and namespace URIs using <code>xslns<\/code>.<\/p>\n<ul>\n<li><code>[xslt_select_xml xml=\"{file}\" strip-namespaces=\"yes\" select=\"\/\/node\" \/]<\/code><\/li>\n<li><code>[xslt_select_xml xml=\"{file}\" xmlns=\"ns1\" ns1=\"{namespace-uri-1}\" select=\"\/\/ns1:node\" \/]<\/code><\/li>\n<li><code>[xslt_select_xml xml=\"{file}\" xmlns=\"ns1 ns2\" ns1=\"{namespace-uri-1}\" ns2=\"{namespace-uri-2}\" select=\"\/\/ns1:node\/ns2:node\" \/]<\/code><\/li>\n<\/ul>\n<h3>WP-CLI<\/h3>\n<p>All three (3) shortcodes have command-line equivalents. They can be used, for instance, to run quick tests. Or they can be used, by piping the outputs into files, to pre-generate results.<\/p>\n<ul>\n<li>\n<pre><code>wp xslt transform_xml\n    --xsl='{file|url|id|slug}'\n    --xml='{file|url|id|slug}'\n    --cache='{minutes, if xsl|xml={url}}'\n    --tidy='{yes|html}' or tidy or --tidy='xml'\n    --{myparam}='{myvalue}'\n    --outfile='{filepath}'\n    --htmlentities or --htmlentities='yes'\n<\/code><\/pre>\n<\/li>\n<li>\n<pre><code>wp xslt select_xml\n    --xml='{file|url|id|slug}'\n    --cache='{minutes, if xml={url}}'\n    --select='{xpath}'\n    --root='{nodename|empty}'\n    --tidy='{yes|html}' or tidy or --tidy='xml'\n    --strip-namespaces='yes' or strip-namespaces\n    --strip-declaration='no'\n    --format='{xml|json}'\n    --htmlentities or --htmlentities='yes'\n<\/code><\/pre>\n<\/li>\n<li>\n<pre><code>wp xslt select_csv\n    --csv='{file|url}'\n    --cache='{minutes, if csv={url}}'\n    --separator=','\n    --enclosure='\"'\n    --escape='\\'\n    --key_row='{row number for column labels}'\n    --col='{return column number(s), letter(s), or label(s)}'\n    --key_col='{col number, letter, or label for key matching}'\n    --key='{value(s) for key_col matching}'\n    --row='{return row number(s)}'\n    --class='{css classname(s) for result table}'\n    --htmlentities or --htmlentities='yes'\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<h3>XSL Stylesheets<\/h3>\n<p>The XSLT Processor plugin includes a number of useful XSL templates that you can include and use in your own projects. They are grouped into five files.<\/p>\n<ul>\n<li>date.xsl : <code>date-format<\/code>, <code>date-microtime<\/code><\/li>\n<li>file.xsl : <code>file-exists-local<\/code>, <code>file-exists-remote<\/code><\/li>\n<li>string.xsl : <code>string-replace<\/code>, <code>string-upper<\/code>, <code>string-lower<\/code>, <code>string-title-case<\/code>, <code>string-trim<\/code>, <code>string-rtrim<\/code>, <code>string-ltrim<\/code>, <code>string-maxlength<\/code>, <code>string-maxwords<\/code>, <code>string-add-slashes<\/code>, <code>string-urlencode<\/code>, <code>string-strip-tags<\/code>, <code>string-nl2br<\/code>, <code>string-entity-decode<\/code>, <code>string-to-nodeset<\/code><\/li>\n<li>util.xsl : <code>util-bytsize<\/code>, <code>util-hash-data<\/code>, <code>util-print-nodes<\/code>, <code>util-print-node-names<\/code>, <code>util-super-global<\/code><\/li>\n<li>wp.xsl : <code>wp-select-xml<\/code>, <code>wp-select-csv<\/code>, <code>wp-post-item<\/code>, <code>wp-post-meta<\/code>, <code>wp-sanitize-title<\/code>, <code>wp-size-format<\/code><\/li>\n<\/ul>\n<h3>Requirements<\/h3>\n<p>The Ten&Two XSLT Processor plugin relies upon PHP\u2019s XSL extension.  If the extension is installed, the XSLT Processor Settings screen will display a message similar to the first message below.  If <code>LIBXSLT_VERSION<\/code> is undefined, all plugin options are disabled automatically and the second message is displayed.<\/p>\n<ul>\n<li><code>PHP's XSL extension is available : XSLT v1.1.32, EXSLT v1.1.32, LIBXML v2.9.4<\/code><\/li>\n<li><code>PHP's XSL extension is NOT available<\/code><\/li>\n<\/ul>\n<p>The XSL extension\u2019s requirements are detailed at php.net \u2013 https:\/\/www.php.net\/manual\/en\/book.xsl.php<\/p>\n<blockquote>\n<p>\u201cThis extension requires the libxml PHP extension. This means passing the \u2013with-libxml,<br \/>\n  or prior to PHP 7.4 the \u2013enable-libxml, configuration flag, although this is implicitly<br \/>\n  accomplished because libxml is enabled by default.<\/p>\n<p>This extension uses libxslt which can be found at \u00bb http:\/\/xmlsoft.org\/XSLT\/. libxslt<br \/>\n  version 1.1.0 or greater is required.\u201d<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Transform and display XML from local and remote sources using PHP's XSL extension.<\/p>\n","protected":false},"author":65,"featured_media":355770,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Ten&Two XSLT Processor - \u8587\u6653\u6735\u63d2\u4ef6\u76ee\u5f55","description":"Transform and display XML from local and remote sources using PHP's XSL extension."},"footnotes":""},"categories":[1],"tags":[729,345,1863,34658,52778],"class_list":["post-225523","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-csv","tag-shortcode","tag-xml","tag-xsl","tag-xslt"],"_links":{"self":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts\/225523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/comments?post=225523"}],"version-history":[{"count":0,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts\/225523\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/media\/355770"}],"wp:attachment":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/media?parent=225523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/categories?post=225523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/tags?post=225523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}