0

Привет. Имеется:

<high>
    <width>
        <field>1</field>
    </width>
    <width>
        <field>1</field>
    </width>
</high>

Нужно сделать:

<high>
      <width field="1"> </width>
      <width field="1"> </width>
</high>

И все это при помощи xsl. Количество width может быть разным, значение field тоже.

1
  • Вопрос решён? Дайте какой-то отклик. 29 мар 2018 в 10:44

1 ответ 1

0
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="*">
        <xsl:copy>
            <xsl:apply-templates select="*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="field">
        <xsl:attribute name="field">
            <xsl:value-of select="."/>
        </xsl:attribute>
    </xsl:template>

</xsl:stylesheet>

Можно добавить ещё один шаблон, чтобы результат в точности до символа соответствовал:

    <xsl:template match="width">
        <xsl:copy>
            <xsl:apply-templates select="*"/>
            <xsl:text> </xsl:text>
        </xsl:copy>
    </xsl:template>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.