如何显示0到多基数的元素?

时间:2015-10-15 21:11:36

标签: xml xslt

我想显示BondTypeTextSplit

我的xml代码

<Integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="http://tsgweb.com" xmlns:IXML="http://tsgweb.com" xmlns:CMCodeQueryHelper="urn:CMCodeQueryHelper" PackageID="Warrant" MessageID="67196706">
<Warrant Op="E" InternalID="1610962157" WarrantID="2140235" xmlns:user="http://tylertechnologies.com">
    <Number>10-CR-15-51 - 2</Number>
    <Setting Op="A">
        <SettingType Op="A" Word="SETBYJDG">Set by Judge</SettingType>
        <Primary Op="A">
            <SettingBondType Op="A">
                <Specified Op="A">
                    <SpecifiedType Op="A" Word="BOND">Appearance Bond</SpecifiedType>
                    <SpecifiedType Op="A" Word="CASHBAIL">Cash Bail</SpecifiedType>
                </Specified>
            </SettingBondType>
            <Amount Op="A">1000</Amount>
        </Primary>
        <Connector Op="A">And</Connector>
        <Split Op="A">
            <SettingBondType Op="A">
                <Specified Op="A">
                    <SpecifiedType Op="A" Word="BOND">Appearance Bond</SpecifiedType>
                    <SpecifiedType Op="A" Word="CASHBAIL">Cash Bail</SpecifiedType>
                </Specified>
            </SettingBondType>
            <Amount Op="A">500</Amount>
        </Split>
        <Split Op="A">
            <SettingBondType Op="A">
                <Specified Op="A">
                    <SpecifiedType Op="A" Word="ATTACHBOND">Attachment Bond</SpecifiedType>
                    <SpecifiedType Op="A" Word="PSURETY">Personal Surety Bond</SpecifiedType>
                </Specified>
            </SettingBondType>
            <Amount Op="A">2000</Amount>
        </Split>
    </Setting>
</Warrant>

我的xslt代码

    <xsl:stylesheet version="1.0" xmlns="http://www.courts.state.mn.us/CourtXML/3" xmlns:msc="http://www.courts.state.mn.us/CourtXML/3" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:mscef="courts.state.mn.us/extfun" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="mscef msxsl msc">
    <xsl:output method="xml" encoding="UTF-8"/>
    <xsl:template name="Warrant_3_6">
        <xsl:param name="pCallType">normal</xsl:param>
        <Warrant>
            <xsl:attribute name="warrantKey"><xsl:value-of select="@WarrantID"/></xsl:attribute>
            <xsl:call-template name="WarrantType_3_6">
                <xsl:with-param name="pCallType">
                    <xsl:value-of select="$pCallType"/>
                </xsl:with-param>
            </xsl:call-template>
            <xsl:if test="string-length(SplitBondConnection)!=0">
                <SplitBond>
                    <SplitBondAssociation>
                        <xsl:value-of select="normalize-space(SplitBondConnection)"/>
                    </SplitBondAssociation>
                    <SplitBondAmount>
                        <xsl:value-of select="mscef:formatCurrency(string(SplitBondAmt))"/>
                    </SplitBondAmount>
                    <SplitBondTypeText>
                        <xsl:attribute name="code"><xsl:value-of select="SplitBondType/@Word"/></xsl:attribute>
                        <xsl:value-of select="SplitBondType"/>
                    </SplitBondTypeText>
                </SplitBond>
            </xsl:if>
        </Warrant>
    </xsl:template>
    <!-- -->
    <xsl:template name="WarrantType_3_6">
        <xsl:param name="pCallType">normal</xsl:param>
        <WarrantNumber>
            <ID>
                <xsl:value-of select="Number"/>
            </ID>
        </WarrantNumber>
        <!--      -->
        <WarrantTypeText>
            <xsl:attribute name="code"><xsl:value-of select="Type/@Word"/></xsl:attribute>
            <xsl:value-of select="Type"/>
        </WarrantTypeText>
        <!--      -->
        <xsl:for-each select="Charge[($pCallType='Deleted') or (Deleted!='true') or (string-length(Deleted)=0)]/
ChargeHistory[($pCallType='Deleted') or (Deleted!='true') or (string-length(Deleted)=0) or (mscef:formatDateTimeNumeric(string(TimestampChange)) &gt; mscef:formatDateTimeNumeric(string(ancestor::Integration/ControlPoint/@Timestamp)))][@Stage='Warrant Issued'][last()]">
            <xsl:call-template name="Charge_3_6"/>
        </xsl:for-each>
        <!--      -->
        <xsl:choose>
            <xsl:when test="Setting/SettingType/@Word='HLDWOBND'">
                <HoldIndicator>true</HoldIndicator>
            </xsl:when>
            <xsl:when test="string-length(TotalBond)!=0">
                <Bond>
                    <BondAmount>
                        <xsl:value-of select="mscef:formatCurrency(string(TotalBond))"/>
                    </BondAmount>
                    <BondType>
                    <xsl:for-each select="Setting/Primary/SettingBondType/Specified">
                        <BondTypeText>
                            <xsl:value-of select="SpecifiedType"/>
                        </BondTypeText>
                        </xsl:for-each>
                    </BondType>
                        <xsl:if test="string-length(TotalFine) > 0">
                        <FineAmount>
                            <xsl:value-of select="mscef:formatCurrency(string(TotalFine))"/>
                        </FineAmount>
                    </xsl:if>
                </Bond>
            </xsl:when>
        </xsl:choose>
        <WarrantConditionTotalAmount>
            <xsl:value-of select="TotalConditionAmount"/>
        </WarrantConditionTotalAmount>
    </xsl:template>
</xsl:stylesheet>

预期输出

<Bond>
    <BondAmount>1000</BondAmount>
    <BondTypeText>
        <BondTypeText Code="BOND">Appearance Bond</BondTypeText>
        <BondTypeText Code="CASHBAIL">Cash Bail</BondTypeText>
    </BondTypeText>
</Bond> 
<SplitBond>     
    <SplitBondAssociation>And</SplitBondAssociation>
    <SplidBondAmount>500</SplidBondAmount>
    <SplitBondType>
        <SettingBondTypeText Code="BOND">Appearance Bond</BondTypeText>
        <SettingBondTypeText Code="CASHBAIL">Cash Bail</BondTypeText>
    </SplitBondType>
</SplitBond>
<SplitBond>     
    <SplitBondAssociation>And</SplitBondAssociation>
    <SplidBondAmount>2000</SplidBondAmount>
    <SplitBondType>
        <SettingBondTypeText Code="ATTACHBOND">Attachment Bond</BondTypeText>
        <SettingBondTypeText Code="PSURETY">Personal Surety Bond</BondTypeText>
    </SplitBondType>
</SplitBond>

1 个答案:

答案 0 :(得分:0)

我认为你的XSLT没有押韵或理由。如果这是您正在寻找的结果,为什么不尝试更简单直接的方法:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/Integration">
    <root>
        <xsl:apply-templates select="Warrant/Setting/Primary"/>
        <xsl:apply-templates select="Warrant/Setting/Split"/>
    </root>
</xsl:template>

<xsl:template match="Primary">
    <Bond>
        <BondAmount>
            <xsl:value-of select="Amount"/>
        </BondAmount>
        <BondTypeText>
            <xsl:apply-templates select="SettingBondType/Specified/SpecifiedType"/>
        </BondTypeText>
    </Bond>         
</xsl:template>

<xsl:template match="Split">
    <SplitBond>     
        <SplitBondAssociation>
            <xsl:value-of select="preceding-sibling::Connector"/>
        </SplitBondAssociation>
        <SplidBondAmount>
            <xsl:value-of select="Amount"/>
        </SplidBondAmount>
        <SplitBondType>
            <xsl:apply-templates select="SettingBondType/Specified/SpecifiedType"/>
        </SplitBondType>
    </SplitBond>
</xsl:template>

<xsl:template match="SpecifiedType">
    <BondTypeText Code="{@Word}">
        <xsl:value-of select="."/>
    </BondTypeText>
</xsl:template>

</xsl:stylesheet>

请注意添加单个根元素:如果没有这个,您的输出将不是XML文档。

相关问题