XML : XSLT transform doesn't access nodes (their attributes) without text content in Islandora MODS to DC transformation

I'm working in Islandora (Drupal) to transform some metadata (MODS to Dublin Core DC) and using XSLT transformation on XML.

The XML looks like this:

  <extension>      <mads:madsCollection>          <mads:mads>              ...              <mads:topic lang="hrv" valueURI="http://www.ncbi.nlm.nih.gov/mesh/D000349">Afrika</mads:topic>              <mads:topic lang="eng">Africa</mads:topic>              ...          </mads:mads>          <mads:mads>              ...              <mads:topic lang="hrv" valueURI="http://www.ncbi.nlm.nih.gov/mesh/D005060">Europa</mads:topic>              <mads:topic lang="eng">Europe</mads:topic>              ...          </mads:mads>          <mads:mads>              ...              <mads:topic lang="hrv" valueURI="http://www.ncbi.nlm.nih.gov/mesh/D001208" />              <mads:topic lang="eng">Asia</mads:topic>              ...          </mads:mads>          <mads:mads>              ...          <mads:topic lang="hrv" valueURI="http://www.ncbi.nlm.nih.gov/mesh/D001315">Australia</mads:topic>          <mads:topic lang="eng"/>              ...          </mads:mads>      </mads:madsCollection>  </extension>    

and XSLT to transform it looks like this:

  <?xml version="1.0" encoding="utf-8"?>  <xsl:stylesheet version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"                  xmlns:mods="http://www.loc.gov/mods/v3" exclude-result-prefixes="mods"                  xmlns:dc="http://purl.org/dc/elements/1.1/"                  xmlns:mads="http://www.loc.gov/mads/v2"                  xmlns:srw_dc="info:srw/schema/1/dc-schema"                  xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">        <xsl:output method="xml" indent="no"/>        <xsl:template match="/">          <!-- WS: updated schema location -->          <xsl:for-each select="mods:mods">              <oai_dc:dc xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">                  <xsl:apply-templates/>              </oai_dc:dc>          </xsl:for-each>      </xsl:template>        <xsl:template match="/mods:mods/mods:extension/mads:madsCollection">          <xsl:apply-templates select="mads:mads/mads:topic" />      </xsl:template>        <xsl:template match="mads:mads/mads:topic">          <dc:subject>              <xsl:attribute name="xml:lang">                  <xsl:value-of select="@lang" />              </xsl:attribute>              <xsl:value-of select="@valueURI" />          </dc:subject>      </xsl:template>     </xsl:stylesheet>    

The output is this:

  <oai_dc:dc xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">      <dc:subject xml:lang="hrv">http://www.ncbi.nlm.nih.gov/mesh/D000349</dc:subject>      <dc:subject xml:lang="eng"/>      <dc:subject xml:lang="hrv">http://www.ncbi.nlm.nih.gov/mesh/D005060</dc:subject>      <dc:subject xml:lang="eng"/>      <dc:subject xml:lang="eng"/>      <dc:subject xml:lang="hrv">http://www.ncbi.nlm.nih.gov/mesh/D001315</dc:subject>  </oai_dc:dc>    

So as you can see, elements without any text content in them (empty elements) XSLT doesn't read. 3rd element doesn't have content in first [@lang='hrv'] mads:topic, and it doesn get in output, but I need that [@valueURI] in output. 4th element doesn't have content in second [@lang='eng'] mads:topic, and it doesn't get in output.

Even if it doesn't have any text content in it, i need to get their attributes [@valueURI] to DC in element dc:subject as text, if that attribute exists. That's not a problem to test if transformation access those nodes, but it obviously doesn't.

So basiclly I need output like this one:

  <oai_dc:dc xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">      <dc:subject xml:lang="hrv">http://www.ncbi.nlm.nih.gov/mesh/D000349</dc:subject>      <dc:subject xml:lang="hrv">http://www.ncbi.nlm.nih.gov/mesh/D005060</dc:subject>      <dc:subject xml:lang="hrv">http://www.ncbi.nlm.nih.gov/mesh/D001208</dc:subject>      <dc:subject xml:lang="hrv">http://www.ncbi.nlm.nih.gov/mesh/D001315</dc:subject>  </oai_dc:dc>    

Why is this one missing?

  <dc:subject xml:lang="hrv">http://www.ncbi.nlm.nih.gov/mesh/D001208</dc:subject>    

No comments:

Post a Comment