Я новичок в XSLT, так что это может быть просто, но я был бы очень признателен за некоторый вклад.Мне нужно скопировать значение атрибутов элементов, которые находятся на уровне Grand parent узла.
Ниже приводится мой 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>
Мне нужно скопировать следующие значения
- Значение атрибута здания в элементе риска / buildingid.
- Значение атрибута местоположения внутри элемента риска / locationid.
- Значение атрибута занятости внутри элемента риска / оккупации.
Ниже приводится мой 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>
Я могу получить данные изатрибуты, но не в состоянии скопировать их в требуемом положении.Любая помощь или предложение будут действительно полезны.