gpt4 book ai didi

xml - 更改元素名称的样式表

转载 作者:行者123 更新时间:2023-12-03 17:04:59 27 4
gpt4 key购买 nike

我有以下 XML

<ExternalAssessmentRequest>

</ExternalAssessmentRequest>

如果有人可以帮助我,真的很感谢你的帮助。
问候

最佳答案

这是一个带有查找表的解决方案,您可以自己填写:

t:\ftemp>type plural.xml 
<ExternalAssessmentRequest>
<ApplicationData Lender="MegaBank">
<LiabilityList>
<RequestedLoans>
<Applicants Percentage="0.5" RelatedIdentifier="Applicant1"/>
<Applicants Percentage="0.5" RelatedIdentifier="Applicant2"/>
<Features Code="Test"/>
</RequestedLoans>
<ExistingLoans>
<Securities RelatedIdentifier="Test"/>
<Applicants Percentage="0.5" RelatedIdentifier="Applicant1"/>
<Applicants Percentage="0.5" RelatedIdentifier="Applicant2"/>
</ExistingLoans>
<OtherLiabilities >
<Applicants Percentage="0.5" RelatedIdentifier="Applicant1"/>
<Applicants Percentage="0.5" RelatedIdentifier="Applicant2"/>
</OtherLiabilities>
<Expenses Amount="50" Description="Train Ticket" Identifier="Expense1" NonRecurring="Yes" Type="Transport" Year="2013">
<Applicants Percentage="0.5" RelatedIdentifier="Applicant1"/>
<Applicants Percentage="0.5" RelatedIdentifier="Applicant2"/>
</Expenses>
</LiabilityList>
<AssetList>
<Assets >
<Applicants Percentage="0.5" RelatedIdentifier="Applicant1"/>
<Applicants Percentage="0.5" RelatedIdentifier="Applicant2"/>
</Assets>
<Funds Amount="1000" Description="Slush Fund" Identifier="Fund1"/>
</AssetList>
<IncomeList>
<Incomes >
<Applicants Percentage="0.5" RelatedIdentifier="Applicant1"/>
<Applicants Percentage="0.5" RelatedIdentifier="Applicant2"/>
</Incomes>
</IncomeList>
<ApplicantList>
<Households AdditionalAdults="0" Boarding="Yes" Children="0" Description="1 Test St, Sydney" Postcode="2000">
<Persons CountryOfResidence="Australia" CustomerDurationInMonths="0" DischargedBankrupts="0" Identifier="Applicant1" Name="John Smith" Partner="Applicant2" Partnered="Yes" PermanentResident="Yes"/>
<Persons CountryOfResidence="Australia" CustomerDurationInMonths="0" DischargedBankrupts="0" Identifier="Applicant2" Name="Jane Smith" Partner="Applicant1" Partnered="Yes" PermanentResident="Yes"/>
<Guarantors/>
</Households>
<Companies Identifier="Company1" Name="Tardis">
<Directors RelatedIdentifier="Applicant1"/>
</Companies>
</ApplicantList>
<FeeList>
<Fees Amount="100" Capitalised="Yes" DateOfPayment="1967-08-13" Description="Application Fee" Identifier="Fee1" PaidAmount="0"/>
</FeeList>
</ApplicationData>
<AdditionalAssessments Lender="MegaBank">
<RequestedLoans Product="Supa Variable" ProductID="Product2"/>
</AdditionalAssessments>
</ExternalAssessmentRequest>
t:\ftemp>call xslt2 plural.xml plural.xsl
<?xml version="1.0" encoding="UTF-8"?><ExternalAssessmentRequest>
<ApplicationData Lender="MegaBank">
<LiabilityList>
<RequestedLoan>
<Applicants Percentage="0.5" RelatedIdentifier="Applicant1"/>
<Applicants Percentage="0.5" RelatedIdentifier="Applicant2"/>
<Features Code="Test"/>
</RequestedLoan>
<ExistingLoans>
<Securities RelatedIdentifier="Test"/>
<Applicants Percentage="0.5" RelatedIdentifier="Applicant1"/>
<Applicants Percentage="0.5" RelatedIdentifier="Applicant2"/>
</ExistingLoans>
<OtherLiabilities>
<Applicants Percentage="0.5" RelatedIdentifier="Applicant1"/>
<Applicants Percentage="0.5" RelatedIdentifier="Applicant2"/>
</OtherLiabilities>
<Expenses Amount="50" Description="Train Ticket" Identifier="Expense1" NonRecurring="Yes" Type="Transport" Year="2013">
<Applicants Percentage="0.5" RelatedIdentifier="Applicant1"/>
<Applicants Percentage="0.5" RelatedIdentifier="Applicant2"/>
</Expenses>
</LiabilityList>
<AssetList>
<Assets>
<Applicants Percentage="0.5" RelatedIdentifier="Applicant1"/>
<Applicants Percentage="0.5" RelatedIdentifier="Applicant2"/>
</Assets>
<Funds Amount="1000" Description="Slush Fund" Identifier="Fund1"/>
</AssetList>
<IncomeList>
<Incomes>
<Applicants Percentage="0.5" RelatedIdentifier="Applicant1"/>
<Applicants Percentage="0.5" RelatedIdentifier="Applicant2"/>
</Incomes>
</IncomeList>
<ApplicantList>
<Households AdditionalAdults="0" Boarding="Yes" Children="0" Description="1 Test St, Sydney" Postcode="2000">
<Persons CountryOfResidence="Australia" CustomerDurationInMonths="0" DischargedBankrupts="0" Identifier="Applicant1" Name="John Smith" Partner="Applicant2" Partnered="Yes" PermanentResident="Yes"/>
<Persons CountryOfResidence="Australia" CustomerDurationInMonths="0" DischargedBankrupts="0" Identifier="Applicant2" Name="Jane Smith" Partner="Applicant1" Partnered="Yes" PermanentResident="Yes"/>
<Guarantors/>
</Households>
<Company Identifier="Company1" Name="Tardis">
<Directors RelatedIdentifier="Applicant1"/>
</Company>
</ApplicantList>
<FeeList>
<Fees Amount="100" Capitalised="Yes" DateOfPayment="1967-08-13" Description="Application Fee" Identifier="Fee1" PaidAmount="0"/>
</FeeList>
</ApplicationData>
<AdditionalAssessments Lender="MegaBank">
<RequestedLoan Product="Supa Variable" ProductID="Product2"/>
</AdditionalAssessments>
</ExternalAssessmentRequest>
t:\ftemp>type plural.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:data="urn:X-data"
exclude-result-prefixes="xsd data"
version="2.0">

<data:convert>
<convert old="RequestedLoans" new="RequestedLoan"/>
<convert old="Companies" new="Company"/>
...add more here...
</data:convert>

<xsl:key name="converts" match="convert" use="@old"/>

<xsl:template match="*[key('converts',name(.),document(''))]">
<xsl:element name="{key('converts',name(.),document(''))/@new}"
namespace="{namespace-uri()}">
<xsl:apply-templates select="@*,node()"/>
</xsl:element>
</xsl:template>

<xsl:template match="@*|node()"><!--identity for all other nodes-->
<xsl:copy>
<xsl:apply-templates select="@*,node()"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
t:\ftemp>rem Done!

编辑以确保在一般解决方案中保留命名空间,而不是假设元素不在命名空间中。感谢 Mads 在他发布的解决方案中首先这样做。

关于xml - 更改元素名称的样式表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18884199/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com