Hot to export xpath search

Questions about XML that are not covered by the other forums should go here.
cleison
Posts: 1

Hot to export xpath search

Thu Feb 11, 2016 8:05 am

How do I export the nodes of my search:

so here is my example xml:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<notes version="1">
   <note player="morgan" label="7" update="1">content</note>
   <note player="jack" label="12" update="1">content</note>
   <note player="jon" label="32" update="2">content</note>
   <note player="mr rain" label="12" update="2">content</note>
   <note player="mr forest" label="32" update="3">content</note>
</notes>


my xpath:

Code: Select all

/notes/note[@update>=2]


now what I want is the possibility to export the search this way, would be easy to hand manually was not for the case that my xml has 3.500.000 lines :shock:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<notes version="1">
   <note player="jon" label="32" update="2">content</note>
   <note player="mr rain" label="12" update="2">content</note>
   <note player="mr forest" label="32" update="3">content</note>
</notes>
Radu
Posts: 5376

Re: Hot to export xpath search

Thu Feb 11, 2016 9:55 am

Hi,

Maybe you can create an XSLT stylesheet with the content something like:

Code: Select all

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml"/>
    <!-- Match document -->
    <xsl:template match="/">
        <xsl:apply-templates mode="copy" select="."/>
    </xsl:template>
    <!-- Deep copy template -->
    <xsl:template match="*|text()|@*" mode="copy">
        <xsl:copy>
            <xsl:apply-templates mode="copy" select="@*"/>
            <xsl:apply-templates mode="copy"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="note[@update &lt; 2]" mode="copy">
        <!-- Ignore content of notes which have the update value less than 2 -->
    </xsl:template>
   
    <!-- Handle default matching -->
    <xsl:template match="*"/>
</xsl:stylesheet>


then create a transformation scenario in Oxygen and apply it over the XML.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Return to “General XML Questions”

Who is online

Users browsing this forum: No registered users and 0 guests