R
R
Rom Black2012-09-04 20:12:08
PHP
Rom Black, 2012-09-04 20:12:08

How to generate xml with data substitution in certain tags?

The essence of the problem: there is a source xml file in which you want to replace the links enclosed in the url tag with your own.
for example, we have offers -> offer -> url
with the value www.heverest.ru/p_plavki_speedo_lycra_brief_6_5cm_...
do I need to get a second xml file or edit the link in the original one so that it looks like
www.mytracker.ru/track.php? query=p_plavki_speedo_l...

<?xml version="1.0" encoding="windows-1251"?><!DOCTYPE yml_catalog SYSTEM "shops.dtd">
<yml_catalog date="2012-09-03 20:30">
<shop>
<name>Heverest.ru - онлайн-гипермаркет</name>
<company>Heverest.ru - онлайн-гипермаркет</company>
<url>http://www.heverest.ru</url>
<currencies><currency id="RUR" rate="1" plus="0"/></currencies>
<categories>
<category id="1">Обувь</category>
.....
<category id="N">Одежда</category>
</categories>
<offers>
<offer id="1" available="false" type="vendor.model"><url>http://www.heverest.ru/p_plavki_speedo_lycra_brief_6_5cm_081000003/</url><price>990.00</price><currencyId>RUR</currencyId><categoryId>1583</categoryId><picture>http://www.heverest.ru/upload/resize_cache/iblock/a62/600_600_0/08100000301_1.jpg</picture><delivery>true</delivery><local_delivery_cost>299</local_delivery_cost><typePrefix>Плавки</typePrefix><vendor>SPEEDO</vendor><model>LYCRA BRIEF 6.5CM</model><description>Плавки SPEEDO LYCRA BRIEF 6.5CM</description></offer>
.....................................
<offer id="99999" available="false" type="vendor.model"><url>http://www.heverest.ru/p_leska_spider_ultra_cast_100_m_100010562/</url><price>120.00</price><currencyId>RUR</currencyId><categoryId>1134</categoryId><picture>http://www.heverest.ru/upload/resize_cache/iblock/847/600_600_0/10001056203_1.jpg</picture><delivery>true</delivery><local_delivery_cost>299</local_delivery_cost><typePrefix>Леска</typePrefix><vendor>Spider</vendor><model>Ultra Cast 100</model><description>Леска Spider Ultra Cast 100 м</description></offer>
</offers>
</shop>
</yml_catalog>

initial xml contains about 4000 offers

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MikhailEdoshin, 2012-09-04
@MrBlack

XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates />
    </xsl:copy>
  </xsl:template>
  <xsl:template match="url">
    <xsl:copy>
      <xsl:text>http://www.mytracker.ru/track.php?query=</xsl:text>
      <xsl:value-of select="substring-after(., "http://heverest.ru/" )" />
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

Apply:
xsltproc this-xslt.xslt source.xml > target.xml

or, for formatting:
xsltproc this-xslt.xslt source.xml | xmllint --format - > target.xml

D
dxRange, 2012-09-04
@dxRange

regular expressions, of course.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question