【发布时间】:2018-12-29 11:16:30
【问题描述】:
我有以下 XML:
<?xml version="1.0" encoding="utf-8"?>
<routes>
<route name="/path/{id}/{name}">
<location>~ ^/path/{id}/{name}$</location>
<methods>
<method>GET</method>
</methods>
<parameters>
<parameter name="id">[a-zA-Z0-9]+</parameter>
<parameter name="name">[a-z]+</parameter>
</parameters>
</route>
</routes>
我想得到以下输出:
~ ^/path/(?<id>[a-zA-Z0-9]+)/(?<name>[a-z]+)$
但目前我有像 ~ ^/path/(?<id>[a-zA-Z0-9]+)/{name}$~ ^/path/{id}/(?<name>[a-z]+)$ 这样使用 XSL 的输出:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl"
version="1.0"
>
<xsl:output method="text" encoding="utf-8"/>
<xsl:template match="routes">
<xsl:apply-templates select="route"/>
</xsl:template>
<xsl:template match="route">
<xsl:apply-templates select="parameters"/>
</xsl:template>
<xsl:template match="parameters">
<xsl:apply-templates select="parameter"/>
</xsl:template>
<xsl:template match="parameter">
<xsl:value-of select="php:function('str_replace', concat('{', @name, '}'), concat('(?<', @name, '>', text(), ')'), string(./../../location))"/>
</xsl:template>
</xsl:stylesheet>
我如何使用重用结果并将其传递给下一次运行?
【问题讨论】: