Copied to clipboard

Flag this post as spam?

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


  • boss98 8 posts 29 karma points
    Apr 13, 2011 @ 12:30
    boss98
    0

    how to create xslt tranform from rss

    I have rss and I need to transform to xml. Here it's my problem. In rss documents there is double elements like this <content:encode>, <wt:time> and etc.

     

    I tried this code:

    <excerpt:encoded><![CDATA[Ljubljana-Dobrunje, Javor, 15.831 m2, zemljiše, od tega 475 m2 zazidljivo.]]></excerpt:encoded>

    like this

    <xsl:value-of select="excerpt:encoded"/>,

    but the validator write me, that there is an error.

    Please help me. How can I make it work

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 13, 2011 @ 19:26
    Jan Skovgaard
    0

    Hi boss98

    It's probably because you need to add a namespace reference to your XSLT file so you're able to parse the XML.

    What does the RSS feed look like? And what does your XSLT file look like?

    /Jan

  • boss98 8 posts 29 karma points
    Apr 14, 2011 @ 10:39
    boss98
    0

    Here is my rss




        <rss version="2.0"
        xmlns:excerpt="http://wordpress.org/export/1.1/excerpt/"
        xmlns:content="http://purl.org/rss/1.0/modules/content/"
        xmlns:wfw="http://wellformedweb.org/CommentAPI/"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:wp="http://wordpress.org/export/1.1/"
    >

    <channel>
        <title>Casa - Hiša nepreminine, d.o.o.</title>
        <link>http://casa.dizajniranje.si</link>;
        <description>Verzija 2.0</description>
        <pubDate>Thu, 07 Apr 2011 19:50:35 +0000</pubDate>
        <language>en</language>
        <wp:wxr_version>1.1</wp:wxr_version>
        <wp:base_site_url>http://casa.dizajniranje.si</wp:base_site_url>
        <wp:base_blog_url>http://casa.dizajniranje.si</wp:base_blog_url>

        <wp:author><wp:author_id>1</wp:author_id><wp:author_login>admin</wp:author_login><wp:author_email>[email protected]</wp:author_email><wp:author_display_name><![CDATA[admin]]></wp:author_display_name><wp:author_first_name><![CDATA[]]></wp:author_first_name><wp:author_last_name><![CDATA[]]></wp:author_last_name></wp:author>


        <generator>http://wordpress.org/?v=3.1</generator>;

        <item>
            <title>SL-14096-S</title>
            <link>casa.dizajniranje.si/.../link>
            <pubDate>Thu, 24 Mar 2011 16:49:47 +0000</pubDate>
            <dc:creator>admin</dc:creator>
            <guid isPermaLink="false">casa.dizajniranje.si/.../guid>
            <description></description>
            <content:encoded><![CDATA[Ljubljana-okolica, Polhov Gradec, 291 m2, samostojna hiša, 1216 m2 zemljiša, zgrajena 2004 do etrte gradbene faze, delno dokonana in vseljena 2007, nadaljnje urejanje notranjosti in okolice v letih 2008 in 2009, P+1+M, JZ lega, vsi prikljuki(KTV, internet, telefon, vodovod, kanalizacija), CK na olje in priprava za ogrevanje na sonno energijo; pritlije obsega garderobo, kopalnico z WC-jem, kuhinjo, hodnik, kurilnico in garao; v prvem nadstropju se nahaja še ena kuhinja, ki ni bila še nikoli rabljena in iz katere je izhod v drvarnico in shrambo, velik dnevno bivalni prostor z zidanim keraminim kaminom in izhodom na teraso (24 m2), 3 spalnice, kopalnica, WC; v mansardi je izdelana spalnica, ostalo nedokonano (narejeni so tlaki, fini omet, vsa napeljava-elektrika, voda, CK); nizki stroški, lahko je tudi dvostanovanjska-primerna za dve druini, vsa infrastruktura v bliini, 10 min do AC prikljuka, ZK urejeno, cena ni konna, moen dogovor glede cene, prodamo. Kontakt: 041/779-662 Simona]]></content:encoded>
            <excerpt:encoded><![CDATA[Hiša / Samostojna
    291 / 1.216 m²; 325.000 €]]></excerpt:encoded>
            <wp:post_id>4</wp:post_id>
            <wp:post_date>2011-03-24 16:49:47</wp:post_date>
            <wp:post_date_gmt>2011-03-24 16:49:47</wp:post_date_gmt>
            <wp:comment_status>closed</wp:comment_status>
            <wp:ping_status>closed</wp:ping_status>
            <wp:post_name>sl-14096-s</wp:post_name>
            <wp:status>publish</wp:status>
            <wp:post_parent>0</wp:post_parent>
            <wp:menu_order>0</wp:menu_order>
            <wp:post_type>woo_estate</wp:post_type>
            <wp:post_password></wp:post_password>
            <wp:is_sticky>0</wp:is_sticky>
            <category domain="propertyfeatures" nicename="bazen"><![CDATA[Bazen]]></category>
            <category domain="propertyfeatures" nicename="dovoz"><![CDATA[Dovoz]]></category>
            <category domain="propertyfeatures" nicename="razgled"><![CDATA[Razgled]]></category>
            <category domain="location" nicename="slovenija"><![CDATA[Slovenija]]></category>
            <category domain="propertyfeatures" nicename="soncna-stran"><![CDATA[Sonna stran]]></category>
            <category domain="post_tag" nicename="stavba"><![CDATA[stavba]]></category>
            <category domain="propertyfeatures" nicename="vrt"><![CDATA[Vrt]]></category>
            <wp:postmeta>
                <wp:meta_key>_edit_last</wp:meta_key>
                <wp:meta_value><![CDATA[1]]></wp:meta_value>
            </wp:postmeta>
            <wp:postmeta>
                <wp:meta_key>image</wp:meta_key>
                <wp:meta_value><![CDATA[casa.dizajniranje.si/.../1.jpg]]></wp:meta_value>
            </wp:postmeta>
            <wp:postmeta>
                <wp:meta_key>garages</wp:meta_key>
                <wp:meta_value><![CDATA[1]]></wp:meta_value>
            </wp:postmeta>
            <wp:postmeta>
                <wp:meta_key>beds</wp:meta_key>
                <wp:meta_value><![CDATA[3]]></wp:meta_value>
            </wp:postmeta>
            <wp:postmeta>
                <wp:meta_key>bathrooms</wp:meta_key>
                <wp:meta_value><![CDATA[2]]></wp:meta_value>
            </wp:postmeta>
            <wp:postmeta>
                <wp:meta_key>sale_type</wp:meta_key>
                <wp:meta_value><![CDATA[sale]]></wp:meta_value>
            </wp:postmeta>
            <wp:postmeta>
                <wp:meta_key>sale_metric</wp:meta_key>
                <wp:meta_value><![CDATA[Once off]]></wp:meta_value>
            </wp:postmeta>
            <wp:postmeta>
                <wp:meta_key>on_show</wp:meta_key>
                <wp:meta_value><![CDATA[true]]></wp:meta_value>
            </wp:postmeta>
            <wp:postmeta>
                <wp:meta_key>seo_follow</wp:meta_key>
                <wp:meta_value><![CDATA[false]]></wp:meta_value>
            </wp:postmeta>
            <wp:postmeta>
                <wp:meta_key>woo_maps_enable</wp:meta_key>
                <wp:meta_value><![CDATA[false]]></wp:meta_value>
            </wp:postmeta>
            <wp:postmeta>
                <wp:meta_key>price</wp:meta_key>
                <wp:meta_value><![CDATA[325000]]></wp:meta_value>
            </wp:postmeta>
            <wp:postmeta>
                <wp:meta_key>size</wp:meta_key>
                <wp:meta_value><![CDATA[291]]></wp:meta_value>
            </wp:postmeta>
            <wp:postmeta>
                <wp:meta_key>address</wp:meta_key>
                <wp:meta_value><![CDATA[Polhov Gradec, okolica Ljubljane]]></wp:meta_value>
            </wp:postmeta>
        </item>
       
    </channel>
    </rss>

  • boss98 8 posts 29 karma points
    Apr 14, 2011 @ 10:49
    boss98
    0

    I have try to transform <content:encoded> from rss to <text> in to xml with <xsl:value-of select="excerpt:encoded"/> but it doesn't work.

    :
    :

    <text>
    <xsl:value-of select="excerpt:encoded"/>

    </text>
    :
    :

  • boss98 8 posts 29 karma points
    Apr 14, 2011 @ 10:55
    boss98
    1

    I think I have found solution:

    in xsl file you must add

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"    xmlns:excerpt="http://wordpress.org/export/1.1/excerpt/"
        xmlns:content="http://purl.org/rss/1.0/modules/content/"
        xmlns:wfw="http://wellformedweb.org/CommentAPI/"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:wp="http://wordpress.org/export/1.1/">

    into <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> line to add namespace reference.

    Jan, thank you for a hint

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 14, 2011 @ 11:22
    Jan Skovgaard
    0

    Hi Boss

    Yep, you need that namespace in your own XSLT in order to make it work :-)

    /Jan

  • boss98 8 posts 29 karma points
    Apr 14, 2011 @ 13:32
    boss98
    0

    Can you help me  transform this part of rss

    <wp:postmeta>
                <wp:meta_key>size</wp:meta_key>
                <wp:meta_value><![CDATA[291]]></wp:meta_value>
            </wp:postmeta>


    into


    <size>291</size> in another xml...

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 14, 2011 @ 22:30
    Jan Skovgaard
    0

    Hi boss98

    What does your current XSLT file look like? I would like to see how you retrieve the other values at the moment so I don't write something thay may be confusing to figure out.

    /Jan

     

  • boss98 8 posts 29 karma points
    Apr 15, 2011 @ 09:22
    boss98
    0

    Curent xsl file is

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Edited by XMLSpy® -->
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"    xmlns:excerpt="http://wordpress.org/export/1.1/excerpt/"
        xmlns:content="http://purl.org/rss/1.0/modules/content/"
        xmlns:wfw="http://wellformedweb.org/CommentAPI/"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:wp="http://wordpress.org/export/1.1/">
        <xsl:template match="/">
            <Trgovina id="xml">
                <izdelki><br />
                    <xsl:for-each select="rss/channel/item">
                        <izdelek><br />
                            <SifraID>
                                <xsl:value-of select="title"/>
                            </SifraID><br />
                            <Title>
                            <xsl:value-of select="excerpt:encoded"/>
                            </Title><br />
                            <url>
                                <xsl:value-of select="link"/>
                            </url><br />
                            <zadnja_osvezitev>
                            <xsl:value-of select="wp:post_date"/>
                            </zadnja_osvezitev>
                            <OglasSI>
                            <xsl:value-of select="content:encoded"/>
                            </OglasSI>
                    
                 
                        <seznamOpreme>
                        <xsl:for-each select="category">
                        <oprema id="{@nicename}"/>
                        </xsl:for-each>
                        </seznamOpreme>                       
                       
                            </izdelek>
                            </xsl:for-each>
                </izdelki>
            </Trgovina>
        </xsl:template>
    </xsl:stylesheet>

     

    I like to add all wp:postmeta parameters  like this: <size>291</size>

  • boss98 8 posts 29 karma points
    Apr 15, 2011 @ 09:24
    boss98
    0

    Thanks Jan for all your help

     

  • boss98 8 posts 29 karma points
    Apr 15, 2011 @ 13:15
    boss98
    0

    Jan, can you still help me  transform this part of rss

    <wp:postmeta>
                <wp:meta_key>size</wp:meta_key>
                <wp:meta_value><![CDATA[291]]></wp:meta_value>
            </wp:postmeta>


    into form like this:


    <size>291</size> in another xml...

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 15, 2011 @ 23:05
    Chriztian Steinmeier
    0

    Hi boss98,

    Add a separate template for this - like this:

    <!-- Build an element with the name of the key, containing the value as content -->
    <xsl:template match="wp:postmeta">
        <xsl:element name="{wp:meta_key}">
            <xsl:value-of select="wp:meta_value" />
        </xsl:element>
    </xsl:template>
    
    and then "call" it, using the apply-templates instruction where you want the elements to be - I'm guessing right after the </izdelek> element:
           ...
            </izdelek>
    
            <xsl:apply-templates select="wp:postmeta" />
    
        </xsl:for-each>               
    </izdelki>
    
    - you might be tempted to try that approach for the rest of the file too :-)
    /Chriztian 
  • boss98 8 posts 29 karma points
    Apr 18, 2011 @ 08:55
    boss98
    0

    Thank you, Chriztian.Your advice was very helpfull.

    How can I rename wp:meta_key ?

    Now I get data like this:

    <price>25000</price>
    <size>23</size>
    etc.

    But I want like this:

    <box1>25000</box1>
    <set_box>23</set_box>

     

    Can I do it or not?

    Best regards, Boss98


Please Sign in or register to post replies

Write your reply to:

Draft