使用 XSLT 1 将 XML 文档转换为 base64
Transform XML document to base64 using XSLT 1
我需要使用 XSLT 1 转换将 XML 文档转换为 base64。
我已尝试使用此模板执行此操作:https://github.com/ilyakharlamov/xslt_base64
这是我的 XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:b64="https://github.com/ilyakharlamov/xslt_base64"
version="1.0">
<xsl:output method="text" encoding="utf-8" />
<xsl:strip-space elements="*"/>
<xsl:include href="base64.xsl"/>
<xsl:template match="/">
<xsl:call-template name="b64:encode" >
<xsl:with-param name="asciiString">
<xsl:copy-of select="." />
</xsl:with-param>
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>
这有效,但它会去除所有 XML 标签并仅对文本进行编码。我需要实际编码所有内容(整个文档,原样)。将输出方法更改为 XML 没有帮助。
根据 Martin Honnen 的评论,我是这样做的:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:b64="https://github.com/ilyakharlamov/xslt_base64"
version="1.0">
<xsl:import href="xml-to-string.xsl"/>
<xsl:output method="text" encoding="utf-8" />
<xsl:strip-space elements="*"/>
<xsl:include href="base64.xsl"/>
<xsl:template match="/">
<xsl:call-template name="b64:encode" >
<xsl:with-param name="asciiString">
<xsl:apply-templates select="." mode="xml-to-string" />
</xsl:with-param>
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>
我需要使用 XSLT 1 转换将 XML 文档转换为 base64。
我已尝试使用此模板执行此操作:https://github.com/ilyakharlamov/xslt_base64
这是我的 XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:b64="https://github.com/ilyakharlamov/xslt_base64"
version="1.0">
<xsl:output method="text" encoding="utf-8" />
<xsl:strip-space elements="*"/>
<xsl:include href="base64.xsl"/>
<xsl:template match="/">
<xsl:call-template name="b64:encode" >
<xsl:with-param name="asciiString">
<xsl:copy-of select="." />
</xsl:with-param>
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>
这有效,但它会去除所有 XML 标签并仅对文本进行编码。我需要实际编码所有内容(整个文档,原样)。将输出方法更改为 XML 没有帮助。
根据 Martin Honnen 的评论,我是这样做的:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:b64="https://github.com/ilyakharlamov/xslt_base64"
version="1.0">
<xsl:import href="xml-to-string.xsl"/>
<xsl:output method="text" encoding="utf-8" />
<xsl:strip-space elements="*"/>
<xsl:include href="base64.xsl"/>
<xsl:template match="/">
<xsl:call-template name="b64:encode" >
<xsl:with-param name="asciiString">
<xsl:apply-templates select="." mode="xml-to-string" />
</xsl:with-param>
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>