问题:我有一个存储在数据库中的XML片段,我想与数据库中的其他几个字段结合使用,并使用PHP中的HTML来呈现它们.
我的解决方案:我有Perl后端脚本
$query = "select id, description, xml_content, name from table where id = '$id'";
Run Code Online (Sandbox Code Playgroud)
然后修改XML以包含这些字段.
$xml_content =~ s|<Record>|<Record name="$name" id="$id" desc="$desc">|i;
Run Code Online (Sandbox Code Playgroud)
然后我使用XSL文件将其转换为
<xsl:output method="html"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form action="info.php" method="get" accept-charset="utf-8">
<label for="id">Display xml for: </label>
<input type="text" name="id" value="" id="id" size="40"/>
<p><input type="submit" value="Display it! →"/></p>
</form>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="doc:Record">
<p>
<xsl:choose>
<xsl:when test="./@none">
XML Content ID <xsl:value-of select="@id"/> NOT FOUND
</xsl:when>
<xsl:otherwise>
XML Content ID <xsl:value-of select="@id"/> Found
<xsl:value-of select="@desc"/> - <xsl:value-of …Run Code Online (Sandbox Code Playgroud)