У меня есть следующий файл XML в качестве входных данных, и для каждого экземпляра элемента <CI_DateTypeCode>
мне нужно изменить значение атрибута @codeListValue
.
Преобразование работает, но я получаю на выходе ненужную/нежелательную новую строку между атрибутами @codeList
и @codeListValue
.
Как видите, в исходном XML-файле нет новой строки между атрибутами. Как избежать такого поведения?
Исходный XML-файл:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="c:\ISO19139_rve.xsl"?>
<MD_Metadata xmlns="http://www.isotc211.org/schemas/2005/gmd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gco="http://www.isotc211.org/schemas/2005/gco" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.isotc211.org/schemas/2005/gmd/gmd.xsd">
<MD_DataIdentification>
<citation>
<CI_Citation>
<title>
<gco:CharacterString>Title</gco:CharacterString>
</title>
<date>
<CI_Date>
<date>
<gco:CharacterString>2014-04-15</gco:CharacterString>
</date>
<dateType>
<CI_DateTypeCode codeList="./resource/codeList.xml#CI_DateTypeCode" codeListValue="Creazione">Creazione</CI_DateTypeCode>
</dateType>
</CI_Date>
</date>
</CI_Citation>
</citation>
</MD_DataIdentification>
</MD_Metadata>
XSL-преобразование:
<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:gco="http://www.isotc211.org/schemas/2005/gco"
xmlns:gmd="http://www.isotc211.org/schemas/2005/gmd"
xmlns="http://www.isotc211.org/schemas/2005/gmd"
>
<xsl:strip-space elements="*"/>
<xsl:output indent="yes" encoding="UTF-8"/>
<!-- identity template -->
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<!-- <CI_DateTypeCode>: @codeListValue attribute values -->
<xsl:param name="pCIDateTypeCodeCreation" select="'creation'"/>
<xsl:param name="pCIDateTypeCodePublication" select="'publication'"/>
<xsl:param name="pCIDateTypeCodeRevision" select="'revision'"/>
<xsl:param name="pCIDateTypeCodeOther" select="''"/>
<!-- override: <CI_DateTypeCode> to apply @codeListValue attribute values -->
<xsl:template match="gmd:CI_DateTypeCode/@codeListValue">
<xsl:choose>
<xsl:when test="lower-case(.) eq 'creazione'">
<xsl:attribute name="codeListValue">
<xsl:value-of select="$pCIDateTypeCodeCreation"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="lower-case(.) eq 'pubblicazione'">
<xsl:attribute name="codeListValue">
<xsl:value-of select="$pCIDateTypeCodePublication"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="lower-case(.) eq 'revisione'">
<xsl:attribute name="codeListValue">
<xsl:value-of select="$pCIDateTypeCodeRevision"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="lower-case(.) eq 'rilievo'">
<xsl:attribute name="codeListValue">
<xsl:value-of select="$pCIDateTypeCodeOther"/>
</xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Фактический вывод XML (см. новую строку с отступом между атрибутами @codeList
и @codeListValue
):
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="c:\ISO19139_rve.xsl"?>
<MD_Metadata xmlns="http://www.isotc211.org/schemas/2005/gmd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gco="http://www.isotc211.org/schemas/2005/gco"
xmlns:gml="http://www.opengis.net/gml"
xmlns:xlink="http://www.w3.org/1999/xlink"
xsi:schemaLocation="http://www.isotc211.org/schemas/2005/gmd/gmd.xsd">
<MD_DataIdentification>
<citation>
<CI_Citation>
<title>
<gco:CharacterString>Title</gco:CharacterString>
</title>
<date>
<CI_Date>
<date>
<gco:CharacterString>2014-04-15</gco:CharacterString>
</date>
<dateType>
<CI_DateTypeCode codeList="./resource/codeList.xml#CI_DateTypeCode"
codeListValue="creation">Creazione</CI_DateTypeCode>
</dateType>
</CI_Date>
</date>
</CI_Citation>
</citation>
</MD_DataIdentification>
</MD_Metadata>
xsl:output
, чтобы не было отступа:<xsl:output indent="no" encoding="UTF-8"/>
- person helderdarocha   schedule 15.04.2014