Page 1 of 1

find and output

Posted: Sat Aug 01, 2015 1:14 pm
by tekno
hi im new on oxygen xml editor using. i have a xml file contains 700+ items. and i want to find only specified label contains "GOO-*" text

input xml:

Code: Select all

<Urunler>
<Urun>
<Kod>356</Kod>
<Baslik><![CDATA[some text in here]]></Baslik>
<Durum>1</Durum>
<AltBaslik><![CDATA[]]></AltBaslik>
<barcode><![CDATA[GOO-024]]></barcode>
<Fiyat>175.000</Fiyat>
<ParaBirimi>TL</ParaBirimi>
<Miktar>0</Miktar>
<UrunOnayi><![CDATA[ yok ]]></UrunOnayi>
<Resim><![CDATA[some text in here]]></Resim>
<Aciklama><![CDATA[<span style="font-weight: bold;">some text in here]]></Aciklama>
<Kategori><![CDATA[El Aletleri]]></Kategori>
</Urun>
. . . . .
</Urunler>
i want a file with only <barcode>label contains GOO-* text
what method is easy to use for this? and how can i do

thanks

Re: find and output

Posted: Wed Aug 05, 2015 12:02 pm
by adrian
HI,

You can apply this XSL stylesheet with Saxon 6.5.5 and obtain a copy of the XML that contains only the Urun entries that have a barcode with 'GOO-', the rest are filtered out.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="1.0">
<xsl:output method="xml" cdata-section-elements="Baslik AltBaslik barcode UrunOnayi Resim Aciklama Kategori"/>

<!-- Match document -->
<xsl:template match="/">
<xsl:apply-templates mode="copy" select="."/>
</xsl:template>
<!-- Deep copy template -->
<xsl:template match="node()|@*" mode="copy">
<xsl:copy>
<xsl:apply-templates mode="copy" select="@*"/>
<xsl:apply-templates mode="copy"/>
</xsl:copy>
</xsl:template>
<!-- Handle default matching -->
<xsl:template match="*"/>

<xsl:template match="Urun" mode="copy">
<xsl:if test="contains(barcode/text(), 'GOO-')">
<xsl:copy>
<xsl:apply-templates mode="copy"/>
</xsl:copy>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Regards,
Adrian