0

I have a problem to translate XML with attributes. XSLT works only when the XML element <Invoice> has no attributes.

In this format is output empty:

<Invoice xmlns="http://isdoc.cz/namespace/2013" version="6.0.1">

Thanks

XML

<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns="http://isdoc.cz/namespace/2013" version="6.0.1">
    <DocumentType>1</DocumentType>
    <ID>202200001</ID>
    <IssueDate>2022-01-31</IssueDate>
</Invoice>

XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:template match="/">
        <Money>     
            <xsl:apply-templates select="Invoice" />
        </Money>
    </xsl:template>

    <xsl:template match="Invoice">
        <xsl:element name="No">
            <xsl:value-of select="ID"/>
        </xsl:element>
        <xsl:element name="Date">
            <xsl:value-of select="IssueDate"/>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

Output

<Money>
    <No>202200001</No>
    <Date>2022-01-31</Date>
</Money>

Final working sollution - create namespace in header

<xsl:stylesheet version="1.0" xmlns:xsl=http://www.w3.org/1999/XSL/Transform xmlns:isdoc=http://isdoc.cz/namespace/2013>

  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />

  <xsl:template match="/">
    <Money>
      <xsl:apply-templates select="isdoc:Invoice" />
    </Money>
  </xsl:template>

  <xsl:template match="isdoc:Invoice">
    <No>
      <xsl:value-of select="isdoc:ID" />
    </No>
    <Date>
      <xsl:value-of select="isdoc:IssueDate" />
    </Date>
  </xsl:template>
</xsl:stylesheet>


Jiko
  • 1
  • 1

0 Answers0