XSL元素匹配

时间:2018-04-19 15:01:29

标签: xml xslt

我是XSL的新手,我正试图从我的XML中获取这些元素。

XSL 1(creditreport.xsl)

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cr="com/truelink/ds/sch/report/truelink/v3" xmlns:d1p1="com/truelink/ds/sch/report/truelink/v3" >
    <xsl:output method="html" indent="yes"/>
    <xsl:param name="IS_SAMPLE" select="'false'"/>
    <xsl:param name="IS_PRINT_VIEW" select="'false'"/>
    <xsl:variable name="FILE_ID" select="110347814"/>
    <xsl:param name="TODAY_DATE" select="'May 23, 2009'"/>
    <xsl:param name="AVAILABLE_DATE" select="'Apr 23, 2009'"/>
    <xsl:include href="crBodyNew.xsl"/>

</xsl:stylesheet>

XSL 2(crBodyNew.xsl)

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:d1p1="com/truelink/ds/sch/report/truelink/v3">

<xsl:template match="/" >

<!-- 3B VantageScoreV6-->
<html>
<head>
<link href="/report3B/stylesheets/base.css" type="text/css" rel="stylesheet"/>
</head>
<body style="margin:0px">



<table id="reportTop" border="0" class="tableBorder" cellpadding="0" cellspacing="0" width="900">
<tr class="crTableHeader">
    <td width="25%">&#160;</td>
    <td class="tranunionHeaderColum" width="25%">TransUnion&#174;</td>
    <td class="experianHeaderColum" width="25%">Experian&#174;</td>
    <td class="equifaxHeaderColum" width="25%">Equifax&#174;</td>
</tr>
<tr>
    <td><b class="crTradelineGroupHeader" id="vscore" align="left">VantageScore&#174; </b></td>
        <td>    
        [TUCVantageScoreV6 - riskScore Value Here]
        </td>
        <td>    
        [EXPVantageScoreV6 - riskScore Value Here]
        </td>
        <td>    
        [EQFVantageScoreV6 - riskScore Value Here]
        </td>
</tr>
</table>
</body>
</html>

</xsl:template>
</xsl:stylesheet>





<table id="reportTop" border="0" class="tableBorder" cellpadding="0" cellspacing="0" width="900">
<tr class="crTableHeader">
    <td width="25%">&#160;</td>
    <td class="tranunionHeaderColum" width="25%">TransUnion&#174;</td>
    <td class="experianHeaderColum" width="25%">Experian&#174;</td>
    <td class="equifaxHeaderColum" width="25%">Equifax&#174;</td>
</tr>
<tr>
    <td><b class="crTradelineGroupHeader" id="vscore" align="left">VantageScore&#174; </b></td>
        <td>    
        [TUCVantageScoreV6 - riskScore Value Here]
        </td>
        <td>    
        [EXPVantageScoreV6 - riskScore Value Here]
        </td>
        <td>    
        [EQFVantageScoreV6 - riskScore Value Here]
        </td>
</tr>
</table>

XML代码段

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="creditReport.xsl" type="text/xsl" ?>
<BundleComponents>
  <BundleComponent>
    <Type>TUCReportV6</Type>
  </BundleComponent>
  <BundleComponent>
    <Type>EQFReportV6</Type>
  </BundleComponent>
  <BundleComponent>
    <Type>EXPReportV6</Type>
  </BundleComponent>
  <BundleComponent>
    <Type>TUCVantageScoreV6</Type>
    <CreditScoreType xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" riskScore="638" scoreName="VantageScore3" populationRank="39">
      <CreditScoreFactor bureauCode="23" FactorType="Negative" xmlns="com/truelink/ds/sch/report/truelink/v3">
        <Factor abbreviation="" description="" symbol="23" rank="100000"/>
        <FactorText>explain: The VantageScore credit score model relies on information in your credit files at the three national credit reporting companies (Equifax, Experian and TransUnion) to generate your score. Your credit file does not have enough credit behavior information about your loans. A mix of different types of open and active credit accounts can have a positive impact on your credit score.</FactorText>
        <FactorText>factor: Lack of sufficient relevant account information</FactorText>
        <FactorText>cando: Maintaining open and active credit accounts in good standing can help improve your credit score.</FactorText>
      </CreditScoreFactor>
    </CreditScoreType>
  </BundleComponent>
  <BundleComponent>
    <Type>EQFVantageScoreV6</Type>
    <CreditScoreType xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" riskScore="586" scoreName="VantageScore3" populationRank="30">
      <CreditScoreFactor bureauCode="23" FactorType="Negative" xmlns="com/truelink/ds/sch/report/truelink/v3">
        <Factor abbreviation="" description="" symbol="23" rank="100000"/>
        <FactorText>Lack of sufficient relevant account information</FactorText>
      </CreditScoreFactor>
    </CreditScoreType>
  </BundleComponent>
  <BundleComponent>
    <Type>EXPVantageScoreV6</Type>
    <CreditScoreType xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" riskScore="628" scoreName="VantageScore3" populationRank="37">
      <CreditScoreFactor bureauCode="12" FactorType="Negative" xmlns="com/truelink/ds/sch/report/truelink/v3">
        <Factor abbreviation="" description="" symbol="12" rank="100000"/>
        <FactorText>The date that you opened your oldest account is too recent</FactorText>
      </CreditScoreFactor>
    </CreditScoreType>
  </BundleComponent>
</BundleComponents>

这些是组件。我确信这对于精通XSL / XSLT的人来说非常容易。我希望从crBodyNew.xsl

括号中看到的XML中获取字段

请帮忙。

谢谢, 肯尼

1 个答案:

答案 0 :(得分:0)

你想要的表达是......

<xsl:value-of select="BundleComponents/BundleComponent[Type='TUCVantageScoreV6']/CreditScoreType/@riskScore" />

同样适用于其他两种类型。

或者,像这样定义一个键......

<xsl:key name="bundles" match="BundleComponent" use="Type" />

然后,您可以将xsl:value-of语句简化为此...

<xsl:value-of select="key('bundles', 'TUCVantageScoreV6')/CreditScoreType/@riskScore" />