これにより、linux ip route list コマンドからの出力が解析されます。それはちょうど私が横たわっていたものです。
コマンドからの出力を「output」という要素でラップする必要があり、スタイル シートはそこから取得します。ここで重要なのは、xpath 2.0 仕様の tokenize コマンドです。その前にどうやってこれを行うことができたのかわかりません。また、これは私が必要としていたものではなかったため、単一のルート要素を作成しません。あなたの場合、スペースで分割する代わりに、Id spli on a ','
<?xml version="1.0" encoding="UTF-8"?>
<xsl:output method="xml" indent="yes" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="//output">
<!-- split things up for each new line -->
<xsl:variable name="line" select="tokenize(.,'\n')"/>
<xsl:for-each select="$line">
<!-- split each line into peices based on space -->
<xsl:variable name="split" select="tokenize(.,' +')"/>
<xsl:if test="count($split) > 1">
<xsl:element name="route">
<xsl:for-each select="$split">
<xsl:choose>
<xsl:when test="position() = 1">
<xsl:attribute name="address" select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="index" select="position()"/>
<xsl:variable name="fieldName" select="."/>
<xsl:if test="$fieldName and position() mod 2 = 0">
<xsl:attribute name="{$fieldName}" select="$split[$index + 1]"/>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:template>