【发布时间】:2019-03-01 11:00:41
【问题描述】:
我是 XSLT 的新手,所以这可能是基本的,但我非常感谢您提供一些意见。我需要复制节点父级元素的属性值。
下面是我的xml
<session>
<data>
<policy>
<DomicileState>NJ</DomicileState>
<PrimaryRatingState>NJ</PrimaryRatingState>
<AvailableNumberIDForCurrentTerm>1</AvailableNumberIDForCurrentTerm>
<EffectiveDate>2019-02-20</EffectiveDate>
<Term>12</Term>
<ExpirationDate>2020-02-20</ExpirationDate>
<line>
<Type>BusinessOwners</Type>
<lineUnderwriting>
<WritingCompany>07</WritingCompany>
</lineUnderwriting>
<limit>
<Type>LiabilityPerOccurenceLimit</Type>
<iValue>500000</iValue>
</limit>
<limit>
<Type>ProductsCompletedAggregateLimit</Type>
<iValue>1000000</iValue>
</limit>
<limit>
<Type>GeneralAggregateLimit</Type>
<iValue>1000000</iValue>
</limit>
<limit>
<Type>MedicalExpensesLimit</Type>
<iValue>0</iValue>
</limit>
<limit>
<Type>PropertyDamageDeductible</Type>
<iValue>0</iValue>
</limit>
<risk>
<locationid></locationid>
<buildingid></buildingid>
<occupancyid></occupancyid>
<!-- <coverage> -->
<!-- <Type>RiskLiability</Type> -->
<!-- <ClassCodeDisplay>7|[65145] Apartment Building - 4 families or fewer, with office occupancy - includes 3- or 4- fami...</ClassCodeDisplay> -->
<!-- </coverage> -->
<!-- <coverage> -->
<!-- <Type>Building</Type> -->
<!-- <limit> -->
<!-- <Type>Standard</Type> -->
<!-- <iValue>299999</iValue> -->
<!-- </limit> -->
<!-- </coverage> -->
</risk>
</line>
<ProductNumber />
<ProfitCenter />
<QuoteNumber />
<PolicyNumber />
<ProductName>194</ProductName>
<ProductNameDisplay>BOP</ProductNameDisplay>
<Status />
<Department>96</Department>
<DepartmentDisplay>Service Stations</DepartmentDisplay>
<TransactionDate>2019-02-01</TransactionDate>
<PolicyType>New</PolicyType>
<policyProcessing>
<CurrentPolicyNumberIdentifier></CurrentPolicyNumberIdentifier>
</policyProcessing>
</policy>
<account>
<Name>Test_XMLRequest_1.2</Name>
<address>
<Address1>23rd Main Suite</Address1>
<Address2>Agoura Hills</Address2>
<City>Newark</City>
<State>NJ</State>
<ZipCode>07001</ZipCode>
</address>
<LoadFromSubmissionIndicator>0</LoadFromSubmissionIndicator>
<PrimaryPhone>1234567890</PrimaryPhone>
<Email>smtpar@gmail.com</Email>
<InsuredDBA />
<Country>UnitedStates</Country>
<POBox />
<location id="locationid">
<address>
<State>NJ</State>
<Address2>Agoura Hills</Address2>
<City>Newark</City>
<ZipCode>07001</ZipCode>
<Address1>23rd Main Suite</Address1>
</address>
<Number>1</Number>
<locationBusinessOwners>
<County>Atlantic</County>
<Territory>001</Territory>
<ProtectionClass>01</ProtectionClass>
<GradeType>IndividuallyInspected</GradeType>
<BuildingCodeEffectivenessGrading>1</BuildingCodeEffectivenessGrading>
</locationBusinessOwners>
</location>
<building id="buildingid">
<YearBuilt>2016</YearBuilt>
<BuildingLocationNumber>1</BuildingLocationNumber>
<LocationBuildingNumber>1</LocationBuildingNumber>
</building >
<occupancy id="occupancyid">
<SearchValueBOP>Building</SearchValueBOP>
<SearchResultsBOP>7|[65145] Apartment Building - 4 families or fewer, with office occupancy - includes 3- or 4- fami...</SearchResultsBOP>
<BOP_SquareFootage>2000</BOP_SquareFootage>
<Eligible>1</Eligible>
</occupancy>
</account>
<policyAdmin>
<transactions>
<transaction>
<Type>New</Type>
<TermPremium></TermPremium>
<PriorPremium></PriorPremium>
<NewPremium></NewPremium>
</transaction>
</transactions>
</policyAdmin>
<userDetails>
<userName>abc@domain.com</userName>
<fullName>Express Admin</fullName>
</userDetails>
<producerinfo>
<Code>83332</Code>
<Name>Test Producer Alive</Name>
</producerinfo>
<agencyDetails>
<agencyID>10003</agencyID>
<name>Businessowners</name>
<entityTypeID>2</entityTypeID>
<entityType>Carrier</entityType>
</agencyDetails>
</data>
</session>
我需要复制以下值
- risk/buildingid 元素中的建筑属性值。
- risk/locationid 元素内的 location 属性值。
- risk/occupancyid 元素内的 occupancy 属性值。
以下是我的 xslt。
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="risk">
<locationid><xsl:value-of select="../../../account/location/@id"/>
</locationid>
<occupancyid><xsl:value-of select="../../../account/occupancy/@id"/>
</occupancyid>
</xsl:template>
</xsl:stylesheet>
电流输出:
<data>
<policy>
<DomicileState>NJ</DomicileState>
<PrimaryRatingState>NJ</PrimaryRatingState>
<AvailableNumberIDForCurrentTerm>1</AvailableNumberIDForCurrentTerm>
<EffectiveDate>2019-02-20</EffectiveDate>
<Term>12</Term>
<ExpirationDate>2020-02-20</ExpirationDate>
<line>
<Type>BusinessOwners</Type>
<lineUnderwriting>
<WritingCompany>07</WritingCompany>
</lineUnderwriting>
<limit>
<Type>LiabilityPerOccurenceLimit</Type>
<iValue>500000</iValue>
</limit>
<limit>
<Type>ProductsCompletedAggregateLimit</Type>
<iValue>1000000</iValue>
</limit>
<limit>
<Type>GeneralAggregateLimit</Type>
<iValue>1000000</iValue>
</limit>
<limit>
<Type>MedicalExpensesLimit</Type>
<iValue>0</iValue>
</limit>
<limit>
<Type>PropertyDamageDeductible</Type>
<iValue>0</iValue>
</limit>
<locationid>locationid</locationid>
<occupancyid>occupancyid</occupancyid>
</line>
预期输出:
<data>
<policy>
<DomicileState>NJ</DomicileState>
<PrimaryRatingState>NJ</PrimaryRatingState>
<AvailableNumberIDForCurrentTerm>1</AvailableNumberIDForCurrentTerm>
<EffectiveDate>2019-02-20</EffectiveDate>
<Term>12</Term>
<ExpirationDate>2020-02-20</ExpirationDate>
<line>
<Type>BusinessOwners</Type>
<lineUnderwriting>
<WritingCompany>07</WritingCompany>
</lineUnderwriting>
<limit>
<Type>LiabilityPerOccurenceLimit</Type>
<iValue>500000</iValue>
</limit>
<limit>
<Type>ProductsCompletedAggregateLimit</Type>
<iValue>1000000</iValue>
</limit>
<limit>
<Type>GeneralAggregateLimit</Type>
<iValue>1000000</iValue>
</limit>
<limit>
<Type>MedicalExpensesLimit</Type>
<iValue>0</iValue>
</limit>
<limit>
<Type>PropertyDamageDeductible</Type>
<iValue>0</iValue>
</limit>
<risk>
<locationid>locationid</locationid>
<occupancyid>occupancyid</occupancyid>
</risk>
</line>
我能够从属性中获取数据,但无法将它们复制到所需的位置。任何帮助或建议都会非常有帮助。
【问题讨论】:
-
您的 xsl 为我工作,您要将属性值复制到哪里?
-
@bdn02 在风险组内部,我已使用当前输出和预期输出更新了我的代码。让我知道是否有帮助