[WordPress] 外掛分享: Ten&Two XSLT Processor

前言介紹

  • 這款 WordPress 外掛「Ten&Two XSLT Processor」是 2024-03-05 上架。
  • 目前有 10 個安裝啟用數。
  • 上一次更新是 2024-08-27,距離現在已有 250 天。
  • 外掛最低要求 WordPress 5.2 以上版本才可以安裝。
  • 外掛要求網站主機運作至少需要 PHP 版本 7.4 以上。
  • 尚未有人給過這款外掛評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

tenandtwo |

外掛標籤

csv | xml | xsl | xslt | shortcode |

內容簡介

總結:
Ten&Two 的 XSLT Processor 外掛將 PHP 的 XSL 擴展功能引入 WordPress。一旦啟用,該外掛會建立三個簡碼 [xslt_transform/], [xslt_select_xml/], 和 [xslt_select_csv/],可以分開或一起使用,從 XML 和 CSV 源頭豐富您的網站內容。此外,該外掛還啟用兩個自訂文章類型 - XSL 樣式表和 XML 文件 - 用於在 WP Admin 內管理和驗證來源。

問題與答案:
1. XSLT Processor 外掛的作用是什麼?
- 答:XSLT Processor 外掛將 PHP 的 XSL 擴展功能引入 WordPress 並建立三個簡碼,可以處理 XML 和 CSV 源頭的資料。

2. XSLT Processor 外掛提供了哪兩種自訂文章類型?
- 答:XSLT Processor 外掛提供了 XSL 樣式表和 XML 文件兩種自訂文章類型,用於管理和驗證來源。

3. [xslt_transform] 簡碼的主要功能是什麼?
- 答:[xslt_transform] 簡碼的主要功能是處理 XML 資料,使用 XSL 樣式表將結果輸出為 HTML、更多的 XML 或簡單的文本。

4. 如何使用 [xslt_select_xml] 簡碼返回 XML 資料的特定選擇?
- 答:通過使用提供的 XPath 表達式,可以使用 [xslt_select_xml] 簡碼返回 XML 資料的特定選擇,也可以在簡碼本身裡指定 XPath。

5. [xslt_select_csv] 簡碼是用來做什麼的?
- 答:[xslt_select_csv] 簡碼是用來將 CSV 檔案資料轉換為 XML,結果可以直接輸出為 HTML 表格,或透過 [xslt_transform/] 進一步處理。

原文外掛簡介

The Ten&Two XSLT Processor plugin brings the power of PHP’s XSL extension to WordPress. Once enabled, the plugin creates three (3) shortcodes – [xslt_transform_xml/], [xslt_select_xml/], and [xslt_select_csv/] – 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 – XSL Stylesheets and XML Documents – for managing and validating sources within WP Admin.
Detailed documentation and sample code can be found at https://plugins.tenandtwo.com/
Custom Post Types
The XSLT Processor plugin provides two (2) custom post types for managing sources within WordPress – XSL Stylesheets and XML Documents. 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.
Shortcode : [xslt_transform_xml/]
[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.

[xslt_transform_xml xsl="{file|url|id|slug}" xml="{file|url|id|slug}" /]
[xslt_transform_xml xsl="{file|url|id|slug}"]...[/xslt_transform_xml]

If either the xsl or xml parameter is left unspecified, defaults are used. The default XML value is . The default XSL stylesheet prints all of the incoming data as HTML. If extra attributes are specified in the shortcode – eg, mykey="myval" – those keys/values are passed along as parameters to the stylesheet – .
Shortcode : [xslt_select_xml/]
[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 :

[xslt_select_xml xml="{file|url|id|slug}" select="{XPath}" /]
[xslt_select_xml xml="{file|url|id|slug}"]{XPath}[/xslt_select_xml]

If the XPath select parameter is left unspecified, the default / is used, which returns the entire document. The default output is format="xml". If format="json" is specified, the result is encoded as a JSON string.
Shortcode : [xslt_select_csv/]
[xslt_select_csv/] is a helper function for converting CSV file data to XML. The result can be output directly as an HTML `

`, or the result can be passed to `[xslt_transform_xml/]` for further processing.

[xslt_select_csv csv="{file|url}" /]
[xslt_select_csv]{csv,data}[/xslt_select_csv]

Three (3) parameters – separator, enclosure, escape – control reading the input. See PHP’s fgetcsv() function for details.

[xslt_select_csv separator="," enclosure="\"" escape="\\" /]

Two (2) parameters – key_row, col – control writing columns to the output. The key_row attribute is optional, but allows labels from that row to be used in col and key_col.

[xslt_select_csv key_row="{num}" col="{num|letter|label}+" /]

Three (3) parameters – row, key_col, key – control writing rows to the output.

[xslt_select_csv row="{num}+" /]
[xslt_select_csv key_col="{num|letter|label}" key="{val}+" /]

Nested Shortcodes
Combine [xslt_transform_xml] with [xslt_select_xml] :

[xslt_transform_xml][xslt_select_xml/][/xslt_transform_xml]

Combine [xslt_transform_xml] with [xslt_select_csv] :

[xslt_transform_xml][xslt_select_csv/][/xslt_transform_xml]

Combine [xslt_transform_xml] with itself using [/xslt_transform_alias] (WP does not support nested shortcodes with identical names) :

[xslt_transform_alias][xslt_transform_xml/][/xslt_transform_alias]

Combine multiple shortcodes/sources to create a single XML Document (see Custom Post Types above) :

[xslt_select_xml xml="f1.xml" /][xslt_select_xml xml="f2.xml" /]

Cache Parameters
When a shortcode specifies a remote file – xml="{url}" or csv="{url}" – that source is cached locally using WP Transients. The default cache duration is set in the XSLT Processor Settings. To override the default, add cache="{minutes}" to the shortcode.

[xslt_transform_xml xml="{url}" cache="{minutes}" /]
[xslt_select_xml xml="{url}" cache="{minutes}" /]
[xslt_select_csv csv="{url}" cache="{minutes}" /]

Namespace Parameters
Within [xslt_select_xml/] the plugin provides two (2) methods for handling XML containing namespaces. The first is to add strip-namespaces to the shortcode. The second method is to add the needed prefixes and namespace URIs using xslns.

[xslt_select_xml xml="{file}" strip-namespaces="yes" select="//node" /]
[xslt_select_xml xml="{file}" xmlns="ns1" ns1="{namespace-uri-1}" select="//ns1:node" /]
[xslt_select_xml xml="{file}" xmlns="ns1 ns2" ns1="{namespace-uri-1}" ns2="{namespace-uri-2}" select="//ns1:node/ns2:node" /]

WP-CLI
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.

wp xslt transform_xml
--xsl='{file|url|id|slug}'
--xml='{file|url|id|slug}'
--cache='{minutes, if xsl|xml={url}}'
--tidy='{yes|html}' or tidy or --tidy='xml'
--{myparam}='{myvalue}'
--outfile='{filepath}'
--htmlentities or --htmlentities='yes'

wp xslt select_xml
--xml='{file|url|id|slug}'
--cache='{minutes, if xml={url}}'
--select='{xpath}'
--root='{nodename|empty}'
--tidy='{yes|html}' or tidy or --tidy='xml'
--strip-namespaces='yes' or strip-namespaces
--strip-declaration='no'
--format='{xml|json}'
--htmlentities or --htmlentities='yes'

wp xslt select_csv
--csv='{file|url}'
--cache='{minutes, if csv={url}}'
--separator=','
--enclosure='\"'
--escape='\\'
--key_row='{row number for column labels}'
--col='{return column number(s), letter(s), or label(s)}'
--key_col='{col number, letter, or label for key matching}'
--key='{value(s) for key_col matching}'
--row='{return row number(s)}'
--class='{css classname(s) for result table}'
--htmlentities or --htmlentities='yes'

XSL Stylesheets
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.

date.xsl : date-format, date-microtime
file.xsl : file-exists-local, file-exists-remote
string.xsl : string-replace, string-upper, string-lower, string-title-case, string-trim, string-rtrim, string-ltrim, string-maxlength, string-maxwords, string-add-slashes, string-urlencode, string-strip-tags, string-nl2br, string-entity-decode, string-to-nodeset
util.xsl : util-bytsize, util-hash-data, util-print-nodes, util-print-node-names, util-super-global
wp.xsl : wp-select-xml, wp-select-csv, wp-post-item, wp-post-meta, wp-sanitize-title, wp-size-format

Requirements
The Ten&Two XSLT Processor plugin relies upon PHP’s XSL extension. If the extension is installed, the XSLT Processor Settings screen will display a message similar to the first message below. If LIBXSLT_VERSION is undefined, all plugin options are disabled automatically and the second message is displayed.

PHP's XSL extension is available : XSLT v1.1.32, EXSLT v1.1.32, LIBXML v2.9.4
PHP's XSL extension is NOT available

The XSL extension’s requirements are detailed at php.net – https://www.php.net/manual/en/book.xsl.php

“This extension requires the libxml PHP extension. This means passing the –with-libxml,
or prior to PHP 7.4 the –enable-libxml, configuration flag, although this is implicitly
accomplished because libxml is enabled by default.
This extension uses libxslt which can be found at » http://xmlsoft.org/XSLT/. libxslt
version 1.1.0 or greater is required.”

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Ten&Two XSLT Processor」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


1.0.5 | 1.0.6 | 1.0.7 | trunk |

延伸相關外掛(你可能也想知道)

  • XML Documents 》這個外掛提供了必要的基礎建設,以添加一種「XML文件」自訂文章類型,它會呈現一個帶有XSLT樣式表的XML文件,而不是常規文章內容。在自定義應用程序中,如果...。
  • Common options for VihvLCC based themes 》這個外掛有兩個用途:, 1. 編輯基於vihvlcc主題的常見選項(啟用/禁用調試器,調試器位置), 2. 在WordPress環境中包含vihvlcc核心,讓您可以使用WordPress插...。

文章
Filter
Apply Filters
Mastodon