XQuery support via Xidel

This commit is contained in:
~lucidiot 2024-02-24 19:46:25 +00:00
parent f447ee9fc1
commit d4317056f2
Signed by: lucidiot
GPG Key ID: 3358C1CA6906FB8D
2 changed files with 131 additions and 1 deletions

View File

@ -216,6 +216,87 @@
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="XidelOutputFormat">
<xs:annotation>
<xs:documentation>
Output format of a `xidel` command.
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:enumeration value="xml">
<xs:annotation>
<xs:documentation>
XML document.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="html">
<xs:annotation>
<xs:documentation>
XHTML document.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="adhoc">
<xs:annotation>
<xs:documentation>
Human-readable representation. This will output the `text()` content of XML nodes, and JSON structures are output as they are, with indentation.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="xml-wrapped">
<xs:annotation>
<xs:documentation>
Human-readable representation, embedded within an XML structure.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="json-wrapped">
<xs:annotation>
<xs:documentation>
Human-readable representation, embedded within a JSON structure.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="XQueryAction">
<xs:annotation>
<xs:documentation>
Run an XQuery script.
</xs:documentation>
</xs:annotation>
<xs:attribute name="path" type="xs:string" use="required">
<xs:annotation>
<xs:documentation>
Path to the XQuery script relative to the project's xquery/ directory.
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="timeout" type="xs:nonNegativeInteger" use="optional" default="60">
<xs:annotation>
<xs:documentation>
Maximum execution time for the script, in seconds. Set to 0 to disable.
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="user-agent" type="xs:string" use="optional" default="itsb/1.0 (+https://tilde.town/~lucidiot/itsb/)">
<xs:annotation>
<xs:documentation>
User-Agent header to send along with any HTTP requests.
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="output-format" type="XidelOutputFormat" use="optional" default="xml">
<xs:annotation>
<xs:documentation>
Format to use to output the script's results.
</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
<xs:group name="Command">
<xs:choice>
<xs:element name="curl" type="CurlCommand" />
@ -244,6 +325,7 @@
</xs:unique>
</xs:element>
<xs:element name="shell" type="ShellCommand" />
<xs:element name="xquery" type="XQueryAction" />
</xs:choice>
</xs:group>

View File

@ -95,6 +95,15 @@ if ! command -v json2xml >/dev/null 2>&1; then
fi
]]></xsl:text>
<xsl:if test="//itsb:xquery">
<xsl:text><![CDATA[
if ! command -v xidel >/dev/null 2>&1; then
echo "xidel is not installed or available in \$PATH." >&2
echo "See <https://www.videlibri.de/xidel.html#downloads> for installation instructions." >&2
exit 1
fi
]]></xsl:text>
</xsl:if>
<xsl:apply-templates
select="//itsb:link[@verify-ssl = 'false' or @verify-ssl = '0'][generate-id() = generate-id(key('ssl-hosts', substring-before(substring-after(text(), 'https://'), '/'))[1])]"
mode="check"
@ -128,7 +137,7 @@ rm "$DIR/.itsb-feedgen"]]></xsl:text>
</xsl:text>
</xsl:if>
<xsl:for-each select="./itsb:curl|./itsb:jq|./itsb:pup|./itsb:json2xml|./itsb:xml2json|./itsb:shell|./itsb:output">
<xsl:for-each select="./itsb:curl|./itsb:jq|./itsb:pup|./itsb:json2xml|./itsb:xml2json|./itsb:shell|./itsb:xquery|./itsb:output">
<xsl:apply-templates select="." />
<xsl:if test="not(position()=last())">
<xsl:text> \
@ -263,6 +272,45 @@ rm "$DIR/.itsb-feedgen"]]></xsl:text>
<xsl:value-of select="text()" />
</xsl:template>
<xsl:template match="itsb:xquery">
<xsl:text>timeout </xsl:text>
<xsl:choose>
<xsl:when test="@timeout">
<xsl:value-of select="@timeout" />
</xsl:when>
<xsl:otherwise>
<xsl:text>60</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text> xidel --silent --trace-stack --wait=1 --user-agent='</xsl:text>
<xsl:call-template name="escape">
<xsl:with-param name="text">
<xsl:choose>
<xsl:when test="@user-agent">
<xsl:value-of select="@user-agent" />
</xsl:when>
<xsl:otherwise>
<xsl:text>itsb/1.0 (+https://tilde.town/~lucidiot/itsb/)</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
<xsl:text>' --output-format=</xsl:text>
<xsl:choose>
<xsl:when test="@output-format">
<xsl:value-of select="@output-format" />
</xsl:when>
<xsl:otherwise>
<xsl:text>xml</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text> --extract-kind=xquery3 --extract-file='xquery/</xsl:text>
<xsl:call-template name="escape">
<xsl:with-param name="text" select="@path" />
</xsl:call-template>
<xsl:text>'</xsl:text>
</xsl:template>
<xsl:template match="itsb:output">
<xsl:text>> $DIR/feeds/</xsl:text>
<xsl:value-of select="text()" />