Solved

generate xml from xsl using xsl v2

Posted on 2013-12-09
8
257 Views
Last Modified: 2013-12-24
Dear all,
I use this <xsl:template name="ignorewhatever" match="template[state = 1]" > 
to select template with state =1
how to select state =1 and template/template_type[type_id=1 ??
Also need to wrapper the xml output with <ROOT>
thanks
0
Comment
Question by:ethar1
  • 4
  • 4
8 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39705905
to wrap the XML output with ROOT

<xsl:template match="/">
<ROOT>
<xsl:apply-templates/>
</ROOT>
</xsl:template>

and the other test
<xsl:template name="ignorewhatever" match="template[state = 1][template_type[type_id=1]]" >
0
 

Author Comment

by:ethar1
ID: 39706042
<xsl:template match="/">
 
<ROOT>

<xsl:template match="template[not(state = 1)]"/>


</ROOT>
</xsl:template>

give an error
0
 

Author Comment

by:ethar1
ID: 39706053
I think  this expression has a problem
match="template[state = 1][template_type[type_id=1]]"
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39706070
The expression does not have a problem.
You made a copying error,
you can't have a template nested inside a template
look at what I posted and what you made from it
0
 

Author Comment

by:ethar1
ID: 39706102
ok, what about this
<xsl:template match="template[not(state = 1)][ template_type[not(type_id=24)]]"/>
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39706201
seems a valid XPath expression
Of course, I have no idea what the source XML is
0
 

Author Comment

by:ethar1
ID: 39706638
	<template id="47253">
		<id>47253</id>
		<state>1</state>
		<price>75</price>
		<exc_price>4500</exc_price>
		<downloads>1</downloads>
		<is_flash>0</is_flash>
		<is_adult>0</is_adult>
		<is_full_site>0</is_full_site>
		<inserted_date>2013-11-05 00:00:00</inserted_date>
		<update_date>2013-11-25 21:33:32</update_date>
		<width>1680px</width>
		<is_real_size>1</is_real_size>
		<template_type>
			<type_id>24</type_id>
			<type_name>Joomla Templates</type_name>
		</template_type>
		<author>
			<author_id>247</author_id>
			<author_nick>Jenny</author_nick>
		</author>
		<live_preview_url>joomla_47253</live_preview_url>
		<package>
			<package_id>248</package_id>
		</package>
		<properties>
			<property>
				<propertyName>Features</propertyName>
				<propertyValues>
					<propertyValue>Admin Panel</propertyValue>
					<propertyValue>Responsive</propertyValue>
				</propertyValues>
			</property>
			<property>
				<propertyName>Animation</propertyName>
				<propertyValues>
					<propertyValue>HTML plus JS</propertyValue>
				</propertyValues>
			</property>
			<property>
				<propertyName>Functionality</propertyName>
				<propertyValues>
					<propertyValue>blog</propertyValue>
				</propertyValues>
			</property>
			<property>
				<propertyName>Layout</propertyName>
				<propertyValues>
					<propertyValue>2 columns</propertyValue>
				</propertyValues>
			</property>
			<property>
				<propertyName>livePreviewURL</propertyName>
				<propertyValues>
					<propertyValue>joomla_47253</propertyValue>
				</propertyValues>
			</property>
			<property>
				<propertyName>width</propertyName>
				<propertyValues>
					<propertyValue>1680px</propertyValue>
				</propertyValues>
			</property>
			<property>
				<propertyName>Language support</propertyName>
				<propertyValues>
					<propertyValue>English</propertyValue>
				</propertyValues>
			</property>
			<property>
				<propertyName>joomla-engine</propertyName>
				<propertyValues>
					<propertyValue>2.5.9</propertyValue>
				</propertyValues>
			</property>
			<property>
				<propertyName>joomla-compatibility</propertyName>
				<propertyValues>
					<propertyValue>2.5.9</propertyValue>
					<propertyValue>2.5.8</propertyValue>
					<propertyValue>2.5.7</propertyValue>
				</propertyValues>
			</property>
			<property>
				<propertyName>Installation</propertyName>
				<propertyValues>
					<propertyValue>Installation and set up instructions are attached (look for Documentation folder).</propertyValue>
				</propertyValues>
			</property>
		</properties>
		<screenshots_list>
			<screenshot>
				<uri>47200/47253-joom-b-p.jpg</uri>
				<filemtime>2013-10-31 05:10:14</filemtime>
			</screenshot>
			<screenshot>
				<uri>47200/47253-rs.jpg</uri>
				<filemtime>2013-10-31 05:10:15</filemtime>
			</screenshot>
			<screenshot>
				<uri>47200/47253-joom-b.jpg</uri>
				<filemtime>2013-10-31 05:10:14</filemtime>
				<main_preview>1</main_preview>
			</screenshot>
			<screenshot>
				<uri>47200/47253-banner.jpg</uri>
				<filemtime>2013-10-31 05:10:14</filemtime>
			</screenshot>
			<screenshot>
				<uri>47200/47253-origin.jpg</uri>
				<filemtime>2013-10-31 05:10:14</filemtime>
			</screenshot>
			<screenshot>
				<uri>47200/47253-original-1200.jpg</uri>
				<filemtime>2013-10-31 05:10:15</filemtime>
			</screenshot>
			<screenshot>
				<uri>47200/47253-modules.jpg</uri>
				<filemtime>2013-10-31 05:10:14</filemtime>
			</screenshot>
			<screenshot>
				<uri>47200/47253-m.jpg</uri>
				<filemtime>2013-10-31 05:10:14</filemtime>
				<small_preview>1</small_preview>
			</screenshot>
			<screenshot>
				<uri>47200/47253-origin-1200.jpg</uri>
				<filemtime>2013-10-31 05:10:14</filemtime>
			</screenshot>
			<screenshot>
				<uri>47200/47253-smart1-responsive.jpg</uri>
				<filemtime>2013-10-31 05:10:15</filemtime>
			</screenshot>
			<screenshot>
				<uri>47200/47253-big.jpg</uri>
				<filemtime>2013-11-22 10:11:28</filemtime>
			</screenshot>
			<screenshot>
				<uri>47200/47253-tablet-responsive.jpg</uri>
				<filemtime>2013-10-31 05:10:15</filemtime>
			</screenshot>
			<screenshot>
				<uri>47200/47253-med.jpg</uri>
				<filemtime>2013-10-31 05:10:14</filemtime>
			</screenshot>
			<screenshot>
				<uri>47200/47253-smart2-responsive.jpg</uri>
				<filemtime>2013-10-31 05:10:15</filemtime>
			</screenshot>
			<screenshot>
				<uri>47200/47253-joom.html</uri>
				<filemtime>2013-10-31 05:10:14</filemtime>
			</screenshot>
			<screenshot>
				<uri>47200/47253-original.jpg</uri>
				<filemtime>2013-10-31 05:10:15</filemtime>
			</screenshot>
		</screenshots_list>
		<keywords>yoga studio club health body mind spirit stress specials services announcement benefits classes practice hatha kripalu yoga basics pilates ashtanga &amp;amp; anusara pre-natal specialized karma teacher training iyengar kids yoga meditation therapeutic</keywords>
		<styles/>
		<categories>
			<category>
				<category_id>14</category_id>
				<category_name>Sport</category_name>
			</category>
		</categories>
		<sources_available_list>
			<source>
				<source_id>3</source_id>
			</source>
			<source>
				<source_id>12</source_id>
			</source>
		</sources_available_list>
		<sources> .PSD&lt;br&gt;.PHP</sources>
		<software_required_list>
			<software>
				<software_id>8</software_id>
			</software>
			<software>
				<software_id>26</software_id>
			</software>
			<software>
				<software_id>53</software_id>
			</software>
			<software>
				<software_id>238</software_id>
			</software>
		</software_required_list>
		<software_required> Adobe Photoshop CS+; Adobe Dreamweaver 8+ (or any php-editor); For uncompressing a template ZIP package:&lt;br&gt; WinZip 9+ (Windows);&lt;br&gt; Stuffit Expander 10+ (Mac); Joomla! 2.5.9</software_required>
		<pages>
			<page>
				<name>Main Page</name>
				<screenshots>
					<scr>
						<description>Real Size Screenshot</description>
						<uri>47200/47253-rs.jpg</uri>
						<scr_type_id>78</scr_type_id>
						<width>970</width>
						<height>280</height>
						<href/>
					</scr>
					<scr>
						<description/>
						<uri>47200/47253-joom.html</uri>
						<scr_type_id>179</scr_type_id>
						<width>430</width>
						<height>60</height>
						<href/>
					</scr>
					<scr>
						<description>Joomla Main Page preview</description>
						<uri>47200/47253-joom-b.jpg</uri>
						<scr_type_id>178</scr_type_id>
						<width>430</width>
						<height>376</height>
						<href/>
					</scr>
					<scr>
						<description>Joomla Modules Positions</description>
						<uri>47200/47253-joom-b-p.jpg</uri>
						<scr_type_id>182</scr_type_id>
						<width>430</width>
						<height>376</height>
						<href/>
					</scr>
					<scr>
						<description>Tablet Layout </description>
						<uri>47200/47253-tablet-responsive.jpg</uri>
						<scr_type_id>298</scr_type_id>
						<width>430</width>
						<height>574</height>
						<href/>
					</scr>
					<scr>
						<description>Smartphone Layout 1 </description>
						<uri>47200/47253-smart1-responsive.jpg</uri>
						<scr_type_id>299</scr_type_id>
						<width>430</width>
						<height>900</height>
						<href/>
					</scr>
					<scr>
						<description>Smartphone Layout 2</description>
						<uri>47200/47253-smart2-responsive.jpg</uri>
						<scr_type_id>300</scr_type_id>
						<width>320</width>
						<height>900</height>
						<href/>
					</scr>
				</screenshots>
			</page>
		</pages>
		<basic_colors>
			<red>0</red>
			<orange>1</orange>
			<yellow>32</yellow>
			<green>38</green>
			<cyan>126</cyan>
			<blue>21</blue>
			<pink>56</pink>
			<purple>50</purple>
			<brown>2</brown>
			<grey>190</grey>
			<white>231</white>
			<black>19</black>
		</basic_colors>
		<colors_mixes>
			<cyan>126</cyan>
			<cyan_grey>23940</cyan_grey>
			<cyan_grey_pink>1340640</cyan_grey_pink>
			<cyan_grey_purple>1197000</cyan_grey_purple>
			<cyan_grey_white>5530140</cyan_grey_white>
			<cyan_pink>7056</cyan_pink>
			<cyan_pink_purple>352800</cyan_pink_purple>
			<cyan_pink_white>1629936</cyan_pink_white>
			<cyan_purple>6300</cyan_purple>
			<cyan_purple_white>1455300</cyan_purple_white>
			<cyan_white>29106</cyan_white>
			<grey>190</grey>
			<grey_pink>10640</grey_pink>
			<grey_pink_purple>532000</grey_pink_purple>
			<grey_pink_white>2457840</grey_pink_white>
			<grey_purple>9500</grey_purple>
			<grey_purple_white>2194500</grey_purple_white>
			<grey_white>43890</grey_white>
			<pink>56</pink>
			<pink_purple>2800</pink_purple>
			<pink_purple_white>646800</pink_purple_white>
			<pink_white>12936</pink_white>
			<purple>50</purple>
			<purple_white>11550</purple_white>
			<white>231</white>
		</colors_mixes>
	</template>

Open in new window

0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 39718010
well, I am not sure whether that helps

Here is an XSLT that wraps your root around the result.
But I have no clue of what else you are trying to do.
Your example has only one template, so what is there to filter.
Please try to explain clear and concise what exactly you need beside the wrapping

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    
    <xsl:strip-space elements="*"/>
    <xsl:output indent="yes"/>
    
    <xsl:template match="/">
        <ROOT>
            <xsl:apply-templates select="node()"/>
        </ROOT>
    </xsl:template>
    
    <xsl:template match="node()">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>
    
</xsl:stylesheet>

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sort order issue from query/json string in DB to xml 5 61
XML & .net 5 51
tutorial for ebay api 3 75
XSLT 1.0 - Finding Substrings from the End of a String 3 38
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question