XSLT 1.0 first date of month
 juls_pro_37
 juls_pro_37
    
    
      - xml
- xsl
 nicht angemeldet
 nicht angemeldetHi, kann mir bitte jemand helfen.
Ich würde gerne immer die letzten beiden Ziffern (eines Datums) auf 01 ändern.
-> Betrifft: "HeaderInformation.BillingPeriod".
Beispiel aktuell: 2023-10-04
Ergebnis sollte folg. sein: 2023-10-01
XML:
<?xml version="1.0" encoding="utf-8"?>
<SALESINVOICE>
  <Interchange>
    <Recipient>1</Recipient>
    <Sender>2</Sender>    
  </Interchange>
  <HeaderInformation>
        <ContractNumber>1</ContractNumber>
    <BillingPeriod>2023-10-04</BillingPeriod>    
  </HeaderInformation>
  <LineInformation>
    <Item>
      <LineNum>1</LineNum>
     </Item> 
     </LineInformation>
</SALESINVOICE>
XSLT:
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl">
 <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
 
  <xsl:strip-space elements="*" /> 
  
 <xsl:template match="node()|@*">
     <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
     </xsl:copy>
 </xsl:template>
 <xsl:template match="*[not(@*|*|comment()|processing-instruction()) and normalize-space()='']"/>
</xsl:stylesheet>
Danke & LG Julian
Hallo Julian,
Ich würde gerne immer die letzten beiden Ziffern (eines Datums) auf 01 ändern.
-> Betrifft: "HeaderInformation.BillingPeriod".
Beispiel aktuell: 2023-10-04
Ergebnis sollte folg. sein: 2023-10-01
XML:
Das kannst du sogar entsprechend auszeichnen und formattieren lassen.
<?xml version="1.0" encoding="utf-8"?> <SALESINVOICE> <Interchange> <Recipient>1</Recipient> <Sender>2</Sender> </Interchange> <HeaderInformation> <ContractNumber>1</ContractNumber> <BillingPeriod>2023-10-04</BillingPeriod> </HeaderInformation> <LineInformation> <Item> <LineNum>1</LineNum> </Item> </LineInformation> </SALESINVOICE>XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl"> <xsl:output method="xml" indent="yes" encoding="UTF-8"/> <xsl:strip-space elements="*" /> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="*[not(@*|*|comment()|processing-instruction()) and normalize-space()='']"/> </xsl:stylesheet>
Das Datum ist aus Sicht von XSLT ein String, d.h. du kannst mit einer Funktion wie substring hier weiterarbeiten.
Viele Grüße
Robert
thx
<xsl:template match="BillingPeriod">
  <xsl:copy>
    <xsl:variable name="BillingPeriod" select="."/>
   <xsl:value-of select="concat(substring(.,1,8),'01')" /> 
  </xsl:copy>
</xsl:template>