我坚持如何为我的属性添加前缀 ext:。我想将ext添加到approximateDateIndicator,currentIndicator,DateOfBirthIndicator,所以它们看起来像这样: 分机:approximateDateIndicator **分机:currentIndicator 分机:DateOfBirthIndicator
我的xslt有一个命名空间 xmlns:ext =“http://www.courts.state.dc.us/ProtectionOrderExtension/1.0”。
我的输出没有添加分机:
<ext:PersonBirthDate>
<ext:PersonBirthDate approximateDateIndicator="false" currentIndicator="false" DateOfBirthIndicator="true">1988-09-01</ext:PersonBirthDate>
<ext:PersonBirthDate approximateDateIndicator="false" currentIndicator="false" DateOfBirthIndicator="true">1988-09-02</ext:PersonBirthDate>
<ext:PersonBirthDate approximateDateIndicator="false" currentIndicator="true" DateOfBirthIndicator="true">1990-01-01</ext:PersonBirthDate>
</ext:PersonBirthDate>
我的xslt代码
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ext="http://www.courts.state.Dc.us/ProtectionOrderExtension/1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template name="ProtectionOrder">
<ext:ProtectionOrder>
<xsl:variable name="vProtectionOrderID">
<xsl:value-of select="@InternalProtectionOrderID"/>
</xsl:variable>
<!--Respondent -->
<xsl:for-each select="RespondentPartyID">
<xsl:for-each select="//CaseParty[(@InternalPartyID=current()/@InternalPartyID) and (Connection[(@Word='RSP') ])]">
<xsl:for-each select="//Party[@InternalPartyID=current()/@InternalPartyID]">
<xsl:call-template name="Respondent">
<xsl:with-param name="pProtectionOrderID">
<xsl:value-of select="$vProtectionOrderID"/>
</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</ext:ProtectionOrder>
</xsl:template>
<!--Template for DateOfBirth for the respondent-->
<xsl:template match="DateOfBirth">
<ext:PersonBirthDate>
<xsl:attribute name="approximateDateIndicator">false</xsl:attribute>
<xsl:attribute name="currentIndicator">false</xsl:attribute>
<xsl:attribute name="DateOfBirthIndicator">true</xsl:attribute>
<xsl:value-of select="mscef:formatDate(string(.))"/>
</ext:PersonBirthDate>
</xsl:template>
<!--Template for DateOfBirth or the respondent where Current = true -->
<xsl:template match="DateOfBirth[@Current='true']">
<ext:PersonBirthDate>
<xsl:attribute name="approximateDateIndicator">false</xsl:attribute>
<xsl:attribute name="currentIndicator">true</xsl:attribute>
<xsl:attribute name="DateOfBirthIndicator">true</xsl:attribute>
<xsl:value-of select="mscef:formatDate(string(.))"/>
</ext:PersonBirthDate>
</xsl:template>
<!--Template for ApproximateDOB for the respondent-->
<xsl:template match="ApproximateDOB">
<ext:PersonBirthDate ext:approximateDateIndicator="true" ext:currentIndicator="{not(../DateOfBirth)}" ext:DateOfBirthIndicator="false">
<xsl:value-of select="mscef:formatDate(string(.))"/>
</ext:PersonBirthDate>
</xsl:template>
<!--Respondent Template-->
<xsl:template name="Respondent">
<xsl:param name="pProtectionOrderID"/>
<ext:Respondent>
<ext:PersonRaceCode>
<xsl:value-of select="//CaseParty[@ID=current()/@ID]/ObservedRace/@Word"/>
</ext:PersonRaceCode>
<!--Guardian -->
<xsl:for-each select="//CaseParty[(Connection[(@Word='GRD')])][1]">
<xsl:for-each select="//Party[@InternalPartyID=current()/@InternalPartyID]">
<xsl:call-template name="Guardian"/>
</xsl:for-each>
</xsl:for-each>
<!-- This is the date of birth of the respondent which is based on the 3 templates above (ApproximateDOB, DateOfBirth[@Current='true'] and DateOfBirth -->
<ext:PersonBirthDate>
<xsl:apply-templates select="ApproximateDOB|DateOfBirth"/>
</ext:PersonBirthDate>
</ext:Respondent>
</xsl:template>
<!--Guardian Template-->
<xsl:template name="Guardian">
<ext:Guardian>
<xsl:for-each select="Race">
<ext:PersonRaceCode>
<xsl:value-of select="@Word"/>
</ext:PersonRaceCode>
</xsl:for-each>
</ext:Guardian>
</xsl:template>
</xsl:stylesheet>
我的xml代码
<Party ID="76">
<Gender Word="F ">Female</Gender>
<NotifyElectronically>0</NotifyElectronically>
<NeedsInterpreter>false</NeedsInterpreter>
<PartyInJailFlag>false</PartyInJailFlag>
<ApproximateDOB>3/4/1956</ApproximateDOB>
<DateOfBirth>04/21/1956</DateOfBirth>
<DateOfBirth Current="true">05/21/1956</DateOfBirth>
</Party>
答案 0 :(得分:1)
由于您的名称空间已经声明并分配了前缀,因此您只需在指定属性名称时添加前缀:
而不是:
<xsl:attribute name="approximateDateIndicator">false</xsl:attribute>
写:
<xsl:attribute name="ext:approximateDateIndicator">false</xsl:attribute>
等