Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Oct 01, 2018 @ 13:49
    Ismail Mayat
    0

    XML import issue

    Hello,

    So I have xml file with 200 records. I am trying to import that. The format of it looks like:

    <results>
      <result web-title="some title">
         <fields>
         <field name="body">lorem ipsum</field>
        </fields>
    </result>
    

    I use xpath //results/result I can map the attributes on result node howver i cannot map fields as they are further down. So i need to transform this xml to simpler format where it is all on level?

    Regards

    Ismail

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 01, 2018 @ 14:05
    Chriztian Steinmeier
    0

    Hi Ismail,

    Does any of the fields have mixed content (i.e., text + tags)?

    /Chriztian

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Oct 01, 2018 @ 14:25
    Ismail Mayat
    0

    Just text, the format is news aritcles taken from guardian via their api see https://open-platform.theguardian.com/documentation/search

    So I only want title and body content fields which is what i am pulling down. I am guessing i will need to update this xml via an xslt transform so everything is at one level.

    regards

    Ismail

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 01, 2018 @ 14:32
    Chriztian Steinmeier
    0

    Alright,

    Try this and maybe modify depending on what you need:

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    >
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:template match="results">
            <results>
                <xsl:apply-templates select="result" />
            </results>
        </xsl:template>
    
        <xsl:template match="result">
            <result>
                <xsl:copy-of select="@web-title" />
                <xsl:attribute name="body">
                    <xsl:value-of select="fields/field[@name = 'body']" />
                </xsl:attribute>
            </result>
        </xsl:template>
    
    </xsl:stylesheet>
    

    /Chriztian

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Oct 01, 2018 @ 14:42
    Ismail Mayat
    0

    woot i dont have to write too much xslt ftw

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 01, 2018 @ 14:57
    Chriztian Steinmeier
    0

    That's right :)

    Problem is, the body field is HTML which is not very well expressed in an attribute...

    /Chriztian

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Oct 01, 2018 @ 15:09
    Ismail Mayat
    0

    just updated so its not attribute.

    Thanks for the help

  • Richard Soeteman 4049 posts 12922 karma points MVP 2x
    Oct 01, 2018 @ 14:49
    Richard Soeteman
    0

    Hi Ismail,

    Indeed CMSImport expects all to be on one level for a document type.

    Best,

    Richard

Please Sign in or register to post replies

Write your reply to:

Draft