xsl:if和xsl:value-of 拼接字符串

本文介绍了一种使用XSLT处理XML数据的方法,重点在于如何根据证件号码提取出生日期信息,并在证件号码不可用时直接展示出生日期。通过XSLT的条件判断和字符串操作实现了这一功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!--如果出身日期不为空-->
<xsl:if test="CSRQ = ''">
<!--截取证件号码-->
    <xsl:value-of select="concat(substring(ZJHM,7,4),'-',substring(ZJHM,11,2),'-',substring(ZJHM,13,2))" />
</xsl:if>
<xsl:value-of select="CSRQ" />

 

<?xml version=“1.0”encoding=“UTF-8”?><xsl:stylesheet version=“3.0”xmlns:xsl=“http:xmlns:fo=“http:xmlns:w=“http:exclude-result-prefixes=“w”><!--增强字体映射--><xsl:variable name="font-mapping"><font w:name="宋体"fo:name="SimSun"/><font w:name="黑体"fo:name="SimHei"/><font w:name="等线"fo:name="DengXian"/></xsl:variable><!--根模板--><xsl:template match="/"><fo:root><fo:layout-master-set><fo:simple-page-master master-name="A4"margin="1in"><fo:region-body margin-top="0.5in"margin-bottom="0.5in"/><fo:region-before extent="0.5in"/><fo:region-after extent="0.5in"/></fo:simple-page-master></fo:layout-master-set><fo:page-sequence master-reference="A4"><fo:flow flow-name="xsl-region-body"><xsl:apply-templates select="//w:body/*"/></fo:flow></fo:page-sequence></fo:root></xsl:template><!--增强段落处理--><xsl:template match="w:p"><fo:block xsl:use-attribute-sets="paragraph-style"><xsl:apply-templates select="w:pPr/w:jc"mode="align"/><xsl:apply-templates select="w:pPr/w:ind"/><xsl:apply-templates select=".//w:r"/></fo:block></xsl:template><!--文本格式处理增强--><xsl:template match="w:r"><fo:inline><xsl:apply-templates select="w:rPr"/><xsl:value-of select="string-join(w:t, '')"/></fo:inline></xsl:template><!--增强字体处理--><xsl:template match="w:rPr"><xsl:variable name="w-font"select="w:rFonts/@w:ascii | w:rFonts/@w:hAnsi"/><xsl:attribute name="font-family"><xsl:value-of select="($font-mapping/font[@w:name = $w-font]/@fo:name, $w-font, 'SimSun')[1]"/></xsl:attribute><xsl:if test="w:sz/@w:val"><xsl:attribute name="font-size"select="w:sz/@w:val * 0.5 || 'pt'"/></xsl:if><xsl:if test="w:color/@w:val != 'auto'"><xsl:attribute name="color"select="'#' || w:color/@w:val"/></xsl:if><xsl:apply-templates select="w:b | w:i | w:u | w:strike"/></xsl:template><!--下划线删除线处理--><xsl:template match="w:u"><xsl:attribute name="text-decoration">underline</xsl:attribute></xsl:template><xsl:template match="w:strike"><xsl:attribute name="text-decoration">line-through</xsl:attribute></xsl:template><!--表格处理增强--><xsl:template match="w:tbl"><fo:table table-layout="fixed"width="100%"><xsl:for-each select="w:tblGrid/w:gridCol"><fo:table-column column-width="{@w:w div 20}pt"/></xsl:for-each><fo:table-body><xsl:apply-templates select="w:tr"/></fo:table-body></fo:table></xsl:template><xsl:template match="w:tr"><fo:table-row><xsl:apply-templates select="w:tc"/></fo:table-row></xsl:template><xsl:template match="w:tc"><fo:table-cell border="1pt solid #000"padding="4pt"><fo:block><xsl:apply-templates select=".//w:p"/></fo:block></fo:table-cell></xsl:template><!--段落对齐处理--><xsl:template match="w:jc"mode="align"><xsl:attribute name="text-align"><xsl:choose><xsl:when test="@w:val = 'center'">center</xsl:when><xsl:when test="@w:val = 'right'">end</xsl:when><xsl:when test="@w:val = 'both'">justify</xsl:when><xsl:otherwise>start</xsl:otherwise></xsl:choose></xsl:attribute></xsl:template><!--段落缩进处理--><xsl:template match="w:ind"><xsl:attribute name="text-indent"><xsl:value-of select="@w:firstLine div 20 || 'pt'"/></xsl:attribute></xsl:template><!--增强段落样式--><xsl:attribute-set name="paragraph-style"><xsl:attribute name="space-after">12pt</xsl:attribute><xsl:attribute name="line-height">1.5</xsl:attribute><xsl:attribute name="text-align">left</xsl:attribute></xsl:attribute-set></xsl:stylesheet>这个不对,xsl:attribute没有select属性
03-11
<?xml version="1.0"encoding="UTF-8"?><xsl:stylesheet version="3.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:fo="http://www.w3.org/1999/XSL/Format"xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"exclude-result-prefixes="w"><!--增强字体映射--><xsl:variable name="font-mapping"><font w:name="宋体"fo:name="SimSun"/><font w:name="黑体"fo:name="SimHei"/><font w:name="等线"fo:name="DengXian"/></xsl:variable><!--根模板--><xsl:template match="/"><fo:root><fo:layout-master-set><fo:simple-page-master master-name="A4"margin="1in"><fo:region-body margin-top="0.5in"margin-bottom="0.5in"/><fo:region-before extent="0.5in"/><fo:region-after extent="0.5in"/></fo:simple-page-master></fo:layout-master-set><fo:page-sequence master-reference="A4"><fo:flow flow-name="xsl-region-body"><xsl:apply-templates select="//w:body/*"/></fo:flow></fo:page-sequence></fo:root></xsl:template><!--增强段落处理--><xsl:template match="w:p"><fo:block xsl:use-attribute-sets="paragraph-style"><xsl:apply-templates select="w:pPr/w:jc"mode="align"/><xsl:apply-templates select="w:pPr/w:ind"/><xsl:apply-templates select=".//w:r"/></fo:block></xsl:template><!--文本格式处理增强--><xsl:template match="w:r"><fo:inline><xsl:apply-templates select="w:rPr"/><xsl:value-of select="string-join(w:t, '')"/></fo:inline></xsl:template><!--增强字体处理--><xsl:template match="w:rPr"><xsl:variable name="w-font"select="(w:rFonts/@w:ascii, w:rFonts/@w:hAnsi)[1]"/><xsl:attribute name="font-family"><xsl:value-of select="($font-mapping/font[@w:name = $w-font]/@fo:name, $w-font, 'SimSun')[1]"/></xsl:attribute><xsl:if test="w:sz/@w:val"><xsl:attribute name="font-size"><xsl:value-of select="concat(w:sz/@w:val * 0.5, 'pt')"/></xsl:attribute></xsl:if><xsl:if test="w:color/@w:val != 'auto'"><xsl:attribute name="color"><xsl:value-of select="concat('#', w:color/@w:val)"/></xsl:attribute></xsl:if><xsl:apply-templates select="w:b | w:i | w:u | w:strike"/></xsl:template><!--下划线删除线处理--><xsl:template match="w:u"><xsl:attribute name="text-decoration">underline</xsl:attribute></xsl:template><xsl:template match="w:strike"><xsl:attribute name="text-decoration">line-through</xsl:attribute></xsl:template><!--表格处理增强--><xsl:template match="w:tbl"><fo:table table-layout="fixed"width="100%"><xsl:for-each select="w:tblGrid/w:gridCol"><fo:table-column column-width="{@w:w div 20}pt"/></xsl:for-each><fo:table-body><xsl:apply-templates select="w:tr"/></fo:table-body></fo:table></xsl:template><xsl:template match="w:tr"><fo:table-row><xsl:apply-templates select="w:tc"/></fo:table-row></xsl:template><xsl:template match="w:tc"><fo:table-cell border="1pt solid #000"padding="4pt"><fo:block><xsl:apply-templates select=".//w:p"/></fo:block></fo:table-cell></xsl:template><!--段落对齐处理--><xsl:template match="w:jc"mode="align"><xsl:attribute name="text-align"><xsl:choose><xsl:when test="@w:val = 'center'">center</xsl:when><xsl:when test="@w:val = 'right'">end</xsl:when><xsl:when test="@w:val = 'both'">justify</xsl:when><xsl:otherwise>start</xsl:otherwise></xsl:choose></xsl:attribute></xsl:template><!--段落缩进处理--><xsl:template match="w:ind"><xsl:attribute name="text-indent"><xsl:value-of select="concat(@w:firstLine div 20, 'pt')"/></xsl:attribute></xsl:template><!--增强段落样式--><xsl:attribute-set name="paragraph-style"><xsl:attribute name="space-after">12pt</xsl:attribute><xsl:attribute name="line-height">1.5</xsl:attribute><xsl:attribute name="text-align">left</xsl:attribute></xsl:attribute-set></xsl:stylesheet>检查这个xlst样式表的问题,一定要注意这是word的xml转xls-fo的xlst样式表,且xslt版本为3.0,请直接给出修改好的全部结果
最新发布
03-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值