XSLT命名空间输出&&内部调用

XSLT命名空间输出问题:

此属性exclude-result-prefixes可以控制命名空间的输出,比如:exclude-result-prefixes="ne xn en"【注意:命名空间前缀用空格分隔】表示在输出中不出现该命名空间的前缀列表{ne, xm, en}。


XSLT中回车换行表示:

<xsl:text>&#10;</xsl:text>

<xsl:text>&#xa;</xsl:text>


XSLT内部调用举例:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="2.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:ne="http://www.3gpp.org/ftp/specs/archive/32_series/32.615#configData"
	xmlns:xn="http://www.3gpp.org/ftp/specs/archive/32_series/32.625#genericNrm"
	xmlns:en="http://www.3gpp.org/ftp/specs/archive/32_series/32.765#eutranNrm"
	exclude-result-prefixes="ne xn en">
	
	<xsl:output method="xml" indent="yes" encoding="UTF-8" />

	<xsl:template match="/">	
		<NrmFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
			xsi:noNamespaceSchemaLocation="NrmFileFormat.xsd">
			<xsl:element name="CM">
			
				<xsl:for-each select="//xn:ManagedElement [*]">
					<xsl:variable name="ManagedBy" select="xn:attributes/xn:ManagedBy" />
					<xsl:variable name="ManagedElementID" select="@id" />

					<xsl:variable name="PrefixDN">
						<xsl:call-template name="substring-first">
							<xsl:with-param name="text" select="$ManagedBy" />
							<xsl:with-param name="splitor1" select="','" />
							<xsl:with-param name="splitor2" select="'\,'" />
						</xsl:call-template>
					</xsl:variable>

					<xsl:attribute name="Dn">
						<xsl:value-of select="concat($PrefixDN, ',ManagedElement=',$ManagedElementID)" />
					</xsl:attribute>
					
					<ManagedElementId>
						<xsl:value-of select="$ManagedElementID" />
					</ManagedElementId>
						
					<UserLabel>
						<xsl:value-of select="en:attributes/en:UserLabel" />
					</UserLabel>						
					
				</xsl:for-each>
				
			</xsl:element>
		</NrmFile>
	</xsl:template>
	
	<xsl:template name="substring-first">
		<xsl:param name="text" />
		<xsl:param name="splitor1" />
		<xsl:param name="splitor2" />
		<xsl:choose>
			<xsl:when test="contains($text, $splitor2)">
				<xsl:value-of select="substring-before($text,$splitor2)" />
			</xsl:when>
			<xsl:otherwise>
				<xsl:choose>
					<xsl:when test="contains($text, $splitor1)">
						<xsl:value-of select="substring-before($text,$splitor1)" />
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="$text" />
					</xsl:otherwise>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>	
	
	<xsl:template name="string-replace-all">
		<xsl:param name="text" />
		<xsl:param name="old" />
		<xsl:param name="new" />
		<xsl:choose>
			<xsl:when test="contains($text, $old)">
				<xsl:value-of select="substring-before($text,$old)" />
				<xsl:value-of select="$new" />
				<xsl:call-template name="string-replace-all">
					<xsl:with-param name="text" select="substring-after($text,$old)" />
					<xsl:with-param name="old" select="$old" />
					<xsl:with-param name="new" select="$new" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$text" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值