次のことを手伝ってください。
非常に異質で大きな入力ファイルがあります。
個々のノードで個々のテストを実行する必要があり、最終的にブール値を出力します。テストは失敗しましたか? または彼らはすべて合格しましたか?
それを行う良い方法はありますか?
以下に例を詳しく説明しました。
入力ファイルの簡単なサンプル:
<?xml version="1.0" encoding="utf-8"?>
<Application>
<PersonApplicants>
<Person ApplicantType="Borrower" ApplicationType="Sole" >
<PersonName FirstName="Jane" Surname="Smith" />
<PersonalDetails CreditHistory="CleanCredit" YearsInCurrentProfession="12">
<Residency ResidencyStatus="Citizen" ResidencyCountry="Australia"/>
</PersonalDetails>
</Person>
<Person ApplicantType="Guarantor" ApplicationType="Sole" >
<PersonName FirstName="John" Surname="Smith" />
</Person>
</PersonApplicants>
<CompanyApplicants>
<Company ApplicantType="Guarantor" ApplicationType="Joint">
<CompanyName CompanyName="C1" TradingName="C1" />
<BusinessDetails YearsInBusiness="19" CreditHistory="CleanCredit" />
</Company>
</CompanyApplicants>
</Application>
各ノードで一連の個々のテストを実行し、テストの少なくとも 1 つが失敗したか、すべてが成功したかを最後に出力します。
出力サンプル xml:
<TestResult>Failed</TestResult>
テストのいずれかが失敗した場合、または
<TestResult>Passed</TestResult>
すべてのテストに合格した場合。
これは私がやろうとしていたことのサンプルです:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:strip-space elements="*" />
<xsl:template match="/">
<TestResult>
<xsl:variable name="fail_test">
<xsl:apply-templates select="Application" />
</xsl:variable>
<xsl:choose>
<!-- If any rule triggers/fails, output the following value "True".-->
<xsl:when test="$fail_test">True</xsl:when>
<!-- Otherwise putput the following value "False"-->
<xsl:otherwise>False</xsl:otherwise>
</xsl:choose>
</TestResult>
</xsl:template>
<xsl:template match="Application">
<xsl:apply-templates select="PersonApplicants"/>
<xsl:apply-templates select="CompanyApplicants"/>
</xsl:template>
<xsl:template match="PersonApplicants">
<!-- Test Rule 1 Have at least one Borrower, Person or Company. -->
<xsl:variable name="var1">
<xsl:choose>
<xsl:when test="//Person/@ApplicantType='Borrower' or //Company/@ApplicantType='Borrower'"><xsl:copy-of select="true()" /></xsl:when>
<xsl:otherwise><xsl:copy-of select="false()" /></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Test Rule 2 Only one applicant allowed for a Sole application, Person or Company. -->
<xsl:variable name="var2">
<xsl:choose>
<xsl:when test="Person/@ApplicationType='Sole'">
<xsl:choose>
<xsl:when test="count(//Person) + count(//Company) = 1"><xsl:copy-of select="true()" /></xsl:when>
<xsl:otherwise><xsl:copy-of select="false()" /></xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise><xsl:copy-of select="true()" /></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- need a way to handle the results on all Person nodes -->
<!-- this is only in here as a placeholder for the correct code -->
<!-- Test child nodes of Person Applicants, i.e Person nodes. -->
<xsl:for-each select="Person">
<xsl:apply-templates select="."/>
</xsl:for-each>
<!--******************************************************************-->
<!--the returned value of the template-->
<xsl:copy-of select="not($var1 and $var2)" />
<!--******************************************************************-->
</xsl:template>
<xsl:template match="Person">
<!-- @ApplicantType LIXI 2.0 node Validation: is required -->
<xsl:variable name="var1">
<xsl:choose>
<xsl:when test="not (@ApplicantType) or string(@ApplicantType) =''"><xsl:copy-of select="true()" /></xsl:when>
<xsl:otherwise><xsl:copy-of select="false()" /></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- @PrimaryApplicant LIXI 2.0 node Validation: PrimaryApplicant is required when Applicant Type is Borrower -->
<xsl:variable name="var2">
<xsl:choose>
<xsl:when test="not (@PrimaryApplicant) or string(@PrimaryApplicant) =''">
<xsl:choose>
<xsl:when test="@ApplicantType='Borrower'"><xsl:copy-of select="true()" /></xsl:when>
<xsl:otherwise><xsl:copy-of select="false()" /></xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise><xsl:copy-of select="true()" /></xsl:otherwise>
</xsl:choose>
<!--the returned value of the template-->
<xsl:copy-of select="not($var1 and $var2)" />
<!--******************************************************************-->
</xsl:template>
</xsl:stylesheet>