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>