如何在代码中获得节点的结果



i有一个XML发票。我想在一年之后写字母W,然后是weetnumber-> yynww。我只得到一年和信函W-> 2019w。我想在我的代码中也有节点周期的结果,但我似乎无法理解。

我已经尝试了以下内容:

<xsl:template match="/">
   <xsl:for-each select="/x:Invoice">
      <xsl:if test="x:Header/x:DocumentDateTime"><xsl:value-of select="concat(substring(x:Header/x:DocumentDateTime,1,4),'W')"/></xsl:if>
      <xsl:if test="x:Line/x:UserArea/x:TimeCard/x:ReportedTime/x:PeriodWeekNum"><xsl:value-of select="x:Line/x:UserArea/x:TimeCard/x:ReportedTime/x:PeriodWeekNum"/></xsl:if>
   </xsl:for-each>
</xsl:template>

这是XML发票

<Invoice xmlns="http://www.openapplications.org/oagis" xsi="http://www.w3.org/2001/XMLSchema-instance" hrx="http://ns.hr-xml.org/2007-04-15" nl="http://ns.hr-xml.org/2007-04-15" schemaLocation="http://www.openapplications.org/oagis ../Invoice.xsd http://ns.hr-xml.org/2007-04-15 InvoiceAdditionalNL.xsd">
<Header>
<DocumentIds>
<DocumentId>
<Id>19068863</Id>
</DocumentId>
</DocumentIds>
<DocumentDateTime>2019-06-18T00:00:00Z</DocumentDateTime>
<ReasonCode>hours</ReasonCode>
<TotalAmount currency="EUR">58.02</TotalAmount>
<PaymentTerms>
<PaymentTermsDate>2019-06-18T00:00:00Z</PaymentTermsDate>
<NumberOfDays>40</NumberOfDays>
</PaymentTerms>
<Parties>
<BillToParty>
<PartyId>
<Id>012634</Id>
</PartyId>
<Name>BLABLABLA</Name>
<Addresses>
<PrimaryAddress>
<AddressLine>BLABLA 17</AddressLine>
<City>BLABLA</City>
<Country>NL</Country>
<PostalCode>2341 DA</PostalCode>
<Telephone>0123435</Telephone>
</PrimaryAddress>
</Addresses>
<Contacts>
<Contact>
<Description>bladieblad</Description>
</Contact>
</Contacts>
</BillToParty>
<CustomerParty>
<PartyId>
<Id>0123333</Id>
</PartyId>
<Name>Aasdsdasd</Name>
<Addresses>
<PrimaryAddress>
<AddressLine>Nasdasd 44</AddressLine>
<City>REasdsad</City>
<Country>NL</Country>
<PostalCode>1111 AA/PostalCode>
<Telephone>01234344545</Telephone>
</PrimaryAddress>
</Addresses>
<Contacts>
<Contact>
<Description>9008</Description>
</Contact>
</Contacts>
</CustomerParty>
<RemitToParty>
<PartyId>
<Id>8</Id>
</PartyId>
<Name>bladieblad BV</Name>
<TaxId>122323421</TaxId>
<Addresses>
<PrimaryAddress>
<AddressLine>Mercudfsdfsdf 1</AddressLine>
<City>Hsdfsdfds</City>
<PostalCode>1111 DD</PostalCode>
<Description>Hertertertntoor</Description>
<Telephone>12344545-50</Telephone>
</PrimaryAddress>
<SecondaryAddress/>
</Addresses>
<Contacts>
<Contact>
<Description>Addfwefw</Description>
<Addresses>
<PrimaryAddress>
<AddressLine>Pwefwefwe 24</AddressLine>
<City>HEwefwefe</City>
<Country>NL</Country>
<PostalCode>1111 DT</PostalCode>
<Description>Vestiging</Description>
<Telephone>121212</Telephone>
</PrimaryAddress>
<SecondaryAddress>
<AddressLine>Pefefefe</AddressLine>
<City>HEfefe</City>
<Country>NL</Country>
<PostalCode>61212 df</PostalCode>
</SecondaryAddress>
</Addresses>
</Contact>
</Contacts>
</RemitToParty>
<SupplierParty>
<PartyId>
<Id>8</Id>
</PartyId>
<Name>Oereere3r</Name>
<TaxId>ererere44B01</TaxId>
<Addresses>
<PrimaryAddress>
<AddressLine>Mefefegfefe 1</AddressLine>
<City>HOefefefe</City>
<PostalCode>2111 HA</PostalCode>
<Description>H3r344343</Description>
<Telephone>0122212120</Telephone>
</PrimaryAddress>
<SecondaryAddress/>
</Addresses>
<Contacts>
<Contact>
<Description>blabla</Description>
<Addresses>
<PrimaryAddress>
<AddressLine>ererer 24</AddressLine>
<City>HererN</City>
<Country>NL</Country>
<PostalCode>6111 LT</PostalCode>
<Description>Ve34343stg</Description>
<Telephone>026 47errer5</Telephone>
</PrimaryAddress>
<SecondaryAddress>
<AddressLine>Pooererer 24</AddressLine>
<City>Hererere</City>
<Country>NL</Country>
<PostalCode>6611 dd</PostalCode>
</SecondaryAddress>
</Addresses>
</Contact>
</Contacts>
</SupplierParty>
</Parties>
<Type>Both</Type>
<Reason>regular</Reason>
<TotalCharges currency="EUR">47.95</TotalCharges>
<TotalTax currency="EUR">10.07</TotalTax>
<Tax>
<TaxAmount currency="EUR">10.07</TaxAmount>
<TaxBaseAmount currency="EUR">47.95</TaxBaseAmount>
<PercentQuantity uom="BTW">21.00</PercentQuantity>
</Tax>
<UserArea>
<StaffingAdditionalData xmlns="http://ns.hr-xml.org/2007-04-15">
<CustomerReportingRequirements>
<PurchaseOrderNumber/>
<CostCenterCode>9523</CostCenterCode>
</CustomerReportingRequirements>
<ReferenceInformation>
<StaffingSupplierId idOwner="StaffingCustomer">
<IdValue>8</IdValue>
</StaffingSupplierId>
<StaffingCustomerId idOwner="StaffingCustomer">
<IdValue>012634</IdValue>
</StaffingCustomerId>
<StaffingCustomerOrgUnitId idOwner="StaffingCustomer">
<IdValue name="Ablabla"/>
</StaffingCustomerOrgUnitId>
</ReferenceInformation>
</StaffingAdditionalData>
<StaffingOrganization typeOfOrganization="Supplier" xmlns="http://ns.hr-xml.org/2007-04-15">
<Organization>
<OrganizationName>Oldedede</OrganizationName>
</Organization>
<PaymentInfo>
<BankAccountInfo>
<BankInfoByJurisdiction bankJurisdiction="NL">
<BankCode>BANKBANK</BankCode>
<BankWindow/>
<BankAccountNumber>NLBDEUBDUEBDEUBD</BankAccountNumber>
<BankAccountKey/>
<BankAccountType>IBAN</BankAccountType>
</BankInfoByJurisdiction>
<BankAccountForeign/>
</BankAccountInfo>
</PaymentInfo>
</StaffingOrganization>
<StaffingOrganizationNL xmlns="http://ns.hr-xml.org/2007-04-15">
<ChamberofCommerceReference>27ededed</ChamberofCommerceReference>
</StaffingOrganizationNL>
</UserArea>
</Header>
<Line>
<LineNumber>1</LineNumber>
<ReasonCode/>
<Charges>
<TotalCharge>
<Total currency="EUR">-815.60</Total>
</TotalCharge>
</Charges>
<DocumentReferences>
<InvoiceDocumentReference>
<DocumentIds>
<DocumentId>
<Id>1edede</Id>
</DocumentId>
</DocumentIds>
</InvoiceDocumentReference>
</DocumentReferences>
<Line>
<LineNumber>1A</LineNumber>
<Charges>
<TotalCharge>
<Total currency="EUR">-775.60</Total>
</TotalCharge>
</Charges>
<Tax>
<PercentQuantity uom="BTW">21.00</PercentQuantity>
</Tax>
<Price>
<Amount currency="EUR">22.16</Amount>
<PerQuantity uom="regular">1</PerQuantity>
</Price>
<ItemQuantity uom="regular">-35.00</ItemQuantity>
</Line>
<Line>
<LineNumber>1B</LineNumber>
<Charges>
<TotalCharge>
<Total currency="EUR">-40.00</Total>
</TotalCharge>
</Charges>
<Tax>
<PercentQuantity uom="BTW">21.00</PercentQuantity>
</Tax>
<Price>
<Amount currency="EUR">8.00</Amount>
<PerQuantity uom="Travel expenses">1</PerQuantity>
</Price>
<ItemQuantity uom="Travel expenses">-5.00</ItemQuantity>
</Line>
<UserArea>
<TimeCard xmlns="http://ns.hr-xml.org/2007-04-15">
<Id idOwner="StaffingCustomer">
<IdValue>Aedede</IdValue>
</Id>
<ReportedResource>
<Person>
<Id idOwner="StaffingCustomer">
<IdValue>151MIET001</IdValue>
</Id>
<PersonName>
<FormattedName>M. edededed</FormattedName>
<LegalName>M. Mdededede</LegalName>
<GivenName>Maededed</GivenName>
<PreferredGivenName>Mdedede</PreferredGivenName>
<FamilyName>Miededed</FamilyName>
</PersonName>
</Person>
</ReportedResource>
<ReportedTime>
<PeriodStartDate>2019-05-20T00:00:00Z</PeriodStartDate>
<PeriodEndDate>2019-05-26T00:00:00Z</PeriodEndDate>
<PeriodWeekNum>21</PeriodWeekNum>
<TimeInterval type="regular" billable="true">
<StartDateTime>2019-05-20T00:00:00Z</StartDateTime>
<EndDateTime>2019-05-26T00:00:00Z</EndDateTime>
<Duration>35.00</Duration>
<RateOrAmount currency="EUR" type="Hourly" multiplier="100.00">22.16</RateOrAmount>
<AdditionalData>
<CustomerReportingRequirements>
<PurchaseOrderLineItem>0</PurchaseOrderLineItem>
</CustomerReportingRequirements>
</AdditionalData>
</TimeInterval>
<Allowance type="Travel expenses" billable="true">
<Id>
<IdValue name="allowance"/>
</Id>
<StartDate>2019-05-20T00:00:00Z</StartDate>
<EndDate>2019-05-26T00:00:00Z</EndDate>
<Amount currency="EUR">8.00</Amount>
<Quantity>5.00</Quantity>
<AdditionalData>
<CustomerReportingRequirements>
<PurchaseOrderLineItem>0</PurchaseOrderLineItem>
</CustomerReportingRequirements>
</AdditionalData>
</Allowance>
</ReportedTime>
<SubmitterInfo>
<SubmittedDateTime>2019-06-19</SubmittedDateTime>
</SubmitterInfo>
<AdditionalData>
<StaffingAdditionalData xmlns="http://ns.hr-xml.org/2007-04-15">
<CustomerReportingRequirements>
<PurchaseOrderNumber/>
<CostCenterCode>9523</CostCenterCode>
<ProjectCode/>
</CustomerReportingRequirements>
<ReferenceInformation>
<AssignmentId idOwner="StaffingCompany">
<IdValue>1510009388</IdValue>
</AssignmentId>
</ReferenceInformation>
</StaffingAdditionalData>
</AdditionalData>
</TimeCard>
<StaffingAdditionalData xmlns="http://ns.hr-xml.org/2007-04-15">
<CustomerReportingRequirements>
<PurchaseOrderNumber/>
<CostCenterCode>9523</CostCenterCode>
<ProjectCode/>
</CustomerReportingRequirements>
</StaffingAdditionalData>
</UserArea>
</Line>
<Line>
<LineNumber>2</LineNumber>
<ReasonCode/>
<Charges>
<TotalCharge>
<Total currency="EUR">863.55</Total>
</TotalCharge>
</Charges>
<Line>
<LineNumber>2A</LineNumber>
<Charges>
<TotalCharge>
<Total currency="EUR">823.55</Total>
</TotalCharge>
</Charges>
<Tax>
<PercentQuantity uom="BTW">21.00</PercentQuantity>
</Tax>
<Price>
<Amount currency="EUR">23.53</Amount>
<PerQuantity uom="regular">1</PerQuantity>
</Price>
<ItemQuantity uom="regular">35.00</ItemQuantity>
</Line>
<Line>
<LineNumber>2B</LineNumber>
<Charges>
<TotalCharge>
<Total currency="EUR">40.00</Total>
</TotalCharge>
</Charges>
<Tax>
<PercentQuantity uom="BTW">21.00</PercentQuantity>
</Tax>
<Price>
<Amount currency="EUR">8.00</Amount>
<PerQuantity uom="Travel expenses">1</PerQuantity>
</Price>
<ItemQuantity uom="Travel expenses">5.00</ItemQuantity>
</Line>
<UserArea>
<TimeCard xmlns="http://ns.hr-xml.org/2007-04-15">
<Id idOwner="StaffingCustomer">
<IdValue/>
</Id>
<ReportedResource>
<Person>
<Id idOwner="StaffingCustomer">
<IdValue>15ededed</IdValue>
</Id>
<PersonName>
<FormattedName>Mdededed</FormattedName>
<LegalName>M. Mideded</LegalName>
<GivenName>Mdededede</GivenName>
<PreferredGivenName>Mdedede</PreferredGivenName>
<FamilyName>Mideedede</FamilyName>
</PersonName>
</Person>
</ReportedResource>
<ReportedTime>
<PeriodStartDate>2019-05-20T00:00:00Z</PeriodStartDate>
<PeriodEndDate>2019-05-26T00:00:00Z</PeriodEndDate>
<PeriodWeekNum>21</PeriodWeekNum>
<TimeInterval type="regular" billable="true">
<StartDateTime>2019-05-20T00:00:00Z</StartDateTime>
<EndDateTime>2019-05-26T00:00:00Z</EndDateTime>
<Duration>35.00</Duration>
<RateOrAmount currency="EUR" type="Hourly" multiplier="100.00">23.53</RateOrAmount>
<AdditionalData>
<CustomerReportingRequirements>
<PurchaseOrderLineItem>0</PurchaseOrderLineItem>
</CustomerReportingRequirements>
</AdditionalData>
</TimeInterval>
<Allowance type="Travel expenses" billable="true">
<Id>
<IdValue name="allowance"/>
</Id>
<StartDate>2019-05-20T00:00:00Z</StartDate>
<EndDate>2019-05-26T00:00:00Z</EndDate>
<Amount currency="EUR">8.00</Amount>
<Quantity>5.00</Quantity>
<AdditionalData>
<CustomerReportingRequirements>
<PurchaseOrderLineItem>0</PurchaseOrderLineItem>
</CustomerReportingRequirements>
</AdditionalData>
</Allowance>
</ReportedTime>
<SubmitterInfo>
<SubmittedDateTime>2019-06-19</SubmittedDateTime>
</SubmitterInfo>
<AdditionalData>
<StaffingAdditionalData xmlns="http://ns.hr-xml.org/2007-04-15">
<CustomerReportingRequirements>
<PurchaseOrderNumber/>
<CostCenterCode>9523</CostCenterCode>
<ProjectCode/>
</CustomerReportingRequirements>
<ReferenceInformation>
<AssignmentId idOwner="StaffingCompany">
<IdValue>1510009552</IdValue>
</AssignmentId>
</ReferenceInformation>
</StaffingAdditionalData>
</AdditionalData>
</TimeCard>
<StaffingAdditionalData xmlns="http://ns.hr-xml.org/2007-04-15">
<CustomerReportingRequirements>
<PurchaseOrderNumber/>
<CostCenterCode>9523</CostCenterCode>
<ProjectCode/>
</CustomerReportingRequirements>
</StaffingAdditionalData>
</UserArea>
</Line>
</Invoice>

我知道XML写得不好,但这是我们得到的XML ..我需要这样做。

预期结果应为2019w21,但实际结果现在是2019w。有人可以帮助我解决我做错了什么?

ps:我删除了机密信息,这就是为什么您看到bladiablad等。

您遇到的主要问题是Timecard及其后代,以及在Invoice

的不同名称空间中
 <TimeCard xmlns="http://ns.hr-xml.org/2007-04-15">

因此,您需要在XSLT中声明该名称空间(任何前缀都会在此处进行。这是URI必须匹配(

(
xmlns:t="http://ns.hr-xml.org/2007-04-15"

那么您的Xpath表达方式如下:

x:Line/x:UserArea/t:TimeCard/t:ReportedTime/t:PeriodWeekNum

在获得最大的星期数方面,您需要用xsl:if替换xsl:for-each,然后可以按降序排序。

<xsl:for-each select="x:Line/x:UserArea/t:TimeCard/t:ReportedTime/t:PeriodWeekNum">
  <xsl:sort data-type="number" order="descending" />
  <xsl:if test="position() = 1">
    <xsl:value-of select="." />
  </xsl:if>
</xsl:for-each>

尝试此完整的XSLT

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:x="http://www.openapplications.org/oagis"
    xmlns:t="http://ns.hr-xml.org/2007-04-15"
    version="1.0">
<xsl:output method="text" />
<xsl:template match="/">
   <xsl:for-each select="/x:Invoice">
      <xsl:if test="x:Header/x:DocumentDateTime"><xsl:value-of select="concat(substring(x:Header/x:DocumentDateTime,1,4),'W')"/></xsl:if>
      <xsl:for-each select="x:Line/x:UserArea/t:TimeCard/t:ReportedTime/t:PeriodWeekNum">
         <xsl:sort data-type="number" order="descending" />
         <xsl:if test="position() = 1">
            <xsl:value-of select="." />
         </xsl:if>
      </xsl:for-each>
   </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

相关内容

  • 没有找到相关文章

最新更新