D
D
Denis2015-06-18 08:58:49
XPath
Denis, 2015-06-18 08:58:49

How to make xslt transformation with check for empty element?

Good afternoon.
Tell me please. There is an xml code, for example

<formats>
  <format gfv="105704">
    <type>1</type>
    <knd>1151078</knd>
  </format>
  <format gfv="105704">
    <type>1</type>
    <knd>1151078</knd>
  </format>  <format gfv="105704">
    <type>1</type>
    <knd></knd>
  </format>
<formats>

I need xls conversion to match gfv and knd. But, so that if knd is not filled, then it is not substituted into the attribute.
Here is what I did:
<xsl:template match="/">
      <formats>
      <xsl:apply-templates select="/formats/format" />
      </formats>
    </xsl:template>
  <xsl:template match="format">
    <xsl:element name="format">
      <xsl:attribute name ="gfv">
        <xsl:apply-templates select="@gfv" />
      </xsl:attribute>
      <xsl:attribute name ="knd">
        <xsl:apply-templates select="knd" />
      </xsl:attribute>
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>

But at the same time, the empty knd attribute is filled, and I need it to be gone

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2015-06-18
@darkmayers

figured out

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question