xml - 我如何将 XLST 日期从 2020-12-30 转换为 20201230
问题描述
我得到一个 XML 文件并尝试共同转换它。我做过的大部分领域。
我得到导入的代码是:
<DeliveryDate>2020-11-03</DeliveryDate>
我的 XLST 是:
<require><xsl:value-of select="PurchaseOrderLine/DeliveryDate"/></require>
问题是格式输出不好。
输入是2020-12-31
,我需要输出20201231
解决方案
一种快速的方法是使用替换功能
<xsl:value-of select="replace(PurchaseOrderLine/DeliveryDate,'-','')"/>
但是你需要 XSLT 2.0 才能工作 (<xsl:stylesheet version="2.0"...)
对于 XLST 1.0,您需要创建一个模板:
<xsl:template name="string-replace-all">
<xsl:param name="text" />
<xsl:param name="replace" />
<xsl:param name="by" />
<xsl:choose>
<xsl:when test="$text = '' or $replace = ''or not($replace)" >
<!-- Prevent this routine from hanging -->
<xsl:value-of select="$text" />
</xsl:when>
<xsl:when test="contains($text, $replace)">
<xsl:value-of select="substring-before($text,$replace)" />
<xsl:value-of select="$by" />
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="substring-after($text,$replace)" />
<xsl:with-param name="replace" select="$replace" />
<xsl:with-param name="by" select="$by" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
并这样称呼它:
<xsl:variable name="newtext">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="$text" />
<xsl:with-param name="replace" select="a" />
<xsl:with-param name="by" select="b" />
</xsl:call-template>
</xsl:variable>
或尝试翻译:
<xsl:variable name="newtext" select="translate(PurchaseOrderLine/DeliveryDate,'-','')"/>
推荐阅读
- jboss - 引起:java.lang.ClassCastException:org.jboss.vfs.protocol.VirtualFileURLConnection 不能转换为 java.net.JarURLConnection
- python - 当我介绍了这些情况时,为什么在遍历树时没有类型错误?
- react-native - 在 Expo 上保存大数据以供离线使用
- python - python发送udp数据包 - 并不总是发送
- sonarqube - 在 Cake Frosting 上的 Cake.Sonar 中出现错误
- ios - 如何在 OS X swift 中关闭前一个视图控制器时从一个 NS 视图控制器移动到另一个?
- python - cv2.COLOR_BGR2HSV 的色调输出与计算值不对应
- javascript - 使用 Rollup 构建自定义 npm 包中的 react-select 崩溃
- antlr - ANTLR4 NEWLINE 在每个表达式,但对于最后一个可选
- java - 使用 Apache LDAP API 在下次登录 Active Directory 时强制更改密码