Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 4th, 2011, 09:21 AM
Registered User
 
Join Date: Aug 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default could any one post xsl code to convert plist to xml using xsl andviceversa to plist

Hi

Iam new to xsl.
iam having plist in the below format to xml using xsl.
The Apple plist file format is a very special kind of xml, so I plan to convert it to a more standard XML file.

Plist code :

In this Plist,the xml output should work for boolean values and array values with seperator comma, .

For example :
Plist :
<key>booleanAnswer</key>
<false/>
<key>imageNameList</key>
<array>
<string>haiiimage</string>
<string>hellostringimage</string>
</array>

xsl :
xsl should parse plist in such a way that it works for boolean and array in a proper xml formatxml:
<booleanAnswer>false </booleanAnswer>
<imageNameList > haiimage , hellosringimage </imageNameLis>

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>surveyUniqueIndentifier</key>
	<string></string>
	<key>storeId</key>
	<string></string>
	<key>answersList</key>
	<array>
		<dict>
			<key>questionId</key>
			<string>qid001</string>
			<key>categoryId</key>
			<string>cid001</string>
			<key>comments</key>
			<string>hai</string>
			<key>booleanAnswer</key>
			<false/>
			<key>imageNameList</key>
			<array>
				<string>helloimage</string>
				<string>haiimage</string>
			</array>
			<key>selectionList</key>
			<array>
				<string>1</string>
				<string>2</string>
			</array>
		</dict>
		<dict>
			<key>questionId</key>
			<string>qid002</string>
			<key>categoryId</key>
			<string>catid002</string>
			<key>comments</key>
			<string>hellocomments</string>
			<key>booleanAnswer</key>
			<false/>
			<key>imageNameList</key>
			<array>
				<string>haiiimage</string>
				<string>hellostringimage</string>
			</array>
			<key>selectionList</key>
			<array>
				<string>a</string>
				<string>b</string>
			</array>
		</dict>
		<dict>
			<key>questionId</key>
			<string>qid003</string>
			<key>categoryId</key>
			<string>catid003</string>
			<key>comments</key>
			<string>commwnt3</string>
			<key>booleanAnswer</key>
			<false/>
			<key>imageNameList</key>
			<array>
				<string>image1</string>
				<string>image2</string>
			</array>
			<key>selectionList</key>
			<array>
				<string>abc</string>
				<string>xyz</string>
			</array>
		</dict>
	</array>
</dict>
</plist>
xsl i have

Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/> 
<xsl:template match="/plist/dict|array/dict">
  	<xsl:apply-templates select="key"/>
</xsl:template>

<xsl:template match="key">
<xsl:variable name='keyvalue'>
<xsl:value-of select='.'/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$keyvalue='booleanAnswer'">
<xsl:element name="{text()}">
 <xsl:if test="following-sibling::false">false</xsl:if>
 <xsl:if test="following-sibling::true">true</xsl:if>
</xsl:element>
</xsl:when>
<xsl:when test="$keyvalue='selectedOptions'">
<xsl:element name="{text()}">
 <xsl:apply-templates select="following-sibling::*"/> 
</xsl:element>

</xsl:when>
<xsl:otherwise>
 <xsl:element name="{text()}">
 <xsl:apply-templates select="following-sibling::*[1]"/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>





Similar Threads
Thread Thread Starter Forum Replies Last Post
help needed for code to convert the plist to xml file and xml file to plistusing xsl venkat880 BOOK: Beginning XSLT and XPath : Transforming XML Documents and Data 0 August 4th, 2011 07:22 AM
Chapter 9 PList Child in Xcode 4? atracksler BOOK: Beginning iOS 4 Application Development 1 July 30th, 2011 01:45 PM
HTML code from XML to display using XSL koenige XSLT 6 October 27th, 2008 08:11 AM
Help needed transforming plist to XML by XSL Vartan XSLT 4 September 28th, 2007 03:11 PM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.