XSL formatting issue
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 6
- Joined: Sun Mar 27, 2005 10:29 pm
XSL formatting issue
Hi all,
I have an xml document which is as follows
I have an xml document which is as follows
Code: Select all
<plist>
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
<string>TextEdit</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>rtf</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>rtf.icns</string>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>text/rtf</string>
</array>
<key>CFBundleTypeName</key>
<string>NSRTFPboardType</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>RTF </string>
</array>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSIsAppleDefaultForType</key>
<true/>
</dict>
</dict>
</plist>
i want the output to look like this
"CFBundleDevelopmentRegion" = "English";
"CFBundleDisplayName" = "TextEdit";
"CFBundleDocumentTypes" = (
{
"CFBundleTypeExtensions" = (
"rtf"
);
"CFBundleTypeIconFile" = "rtf.icns";
"CFBundleTypeMIMETypes" = (
"text/rtf"
);
and so on.
does anyone have any ideas???
-
- Posts: 6
- Joined: Sun Mar 27, 2005 10:29 pm
Re: XSL formatting issue
sxxx wrote:Hi all,
I have an xml document which is as follows
Code: Select all
<plist>
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
<string>TextEdit</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>rtf</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>rtf.icns</string>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>text/rtf</string>
</array>
<key>CFBundleTypeName</key>
<string>NSRTFPboardType</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>RTF </string>
</array>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSIsAppleDefaultForType</key>
<true/>
</dict>
</dict>
</plist>
i want the output to look like this
"CFBundleDevelopmentRegion" = "English";
"CFBundleDisplayName" = "TextEdit";
"CFBundleDocumentTypes" = (
{
"CFBundleTypeExtensions" = (
"rtf"
);
"CFBundleTypeIconFile" = "rtf.icns";
"CFBundleTypeMIMETypes" = (
"text/rtf"
);
and so on.
i need to have a xsl document to do this formatting
does anyone have any ideas???
-
- Posts: 5
- Joined: Wed Jan 05, 2005 1:07 pm
i think it would be easier if you change your xml adding an 'item' tag:
i have this output:
created with this xslt (i know about the missing line breaks, but that's the only way i get the resulting output with 'xsltproc'):
Code: Select all
<dict>
<item>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
</item>
</dict>
Code: Select all
"CFBundleDevelopmentRegion" = "English"
"CFBundleDisplayName" = "English"
"CFBundleDocumentTypes" = "English"
{
"CFBundleTypeExtensions" = (
"rtf"
);
"CFBundleTypeIconFile" = (
"rtf"
);
"CFBundleTypeMIMETypes" = (
"rtf"
);
"CFBundleTypeName" = (
"rtf"
);
"CFBundleTypeOSTypes" = (
"rtf"
);
"CFBundleTypeRole" = (
"rtf"
);
"LSIsAppleDefaultForType" = (
"rtf"
);
}
Code: Select all
<xsl:output method="text"/>
<xsl:template match="/plist">
<xsl:apply-templates select="dict/key" />
{<xsl:text>
</xsl:text>  <xsl:apply-templates select="dict/array/dict/key" mode="second"/>}
</xsl:template>
<xsl:template match="key">"<xsl:value-of select="." />" = "<xsl:value-of select="../string" />"<xsl:text>
</xsl:text></xsl:template>
<xsl:template match="key" mode="second">"<xsl:value-of select="." />" = (<xsl:text>
</xsl:text>  "<xsl:value-of select="../array/string" />"<xsl:text>
</xsl:text>);<xsl:text>
</xsl:text></xsl:template>
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi,
The following stylesheet should generate what you want including the indents.
Best Regards,
George
The following stylesheet should generate what you want including the indents.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template name="doIndent">
<xsl:param name="indent" select="0"/>
<xsl:if test="$indent>0">
<xsl:text> </xsl:text>
<xsl:call-template name="doIndent">
<xsl:with-param name="indent" select="$indent - 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="plist">
<xsl:apply-templates>
<xsl:with-param name="indent" select="0"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="dict">
<xsl:param name="indent" select="0"/>
<xsl:call-template name="doIndent">
<xsl:with-param name="indent" select="$indent"/>
</xsl:call-template>
<xsl:text>{
</xsl:text>
<xsl:apply-templates select="key">
<xsl:with-param name="indent" select="$indent+1"/>
</xsl:apply-templates>
<xsl:call-template name="doIndent">
<xsl:with-param name="indent" select="$indent"/>
</xsl:call-template>
<xsl:text>}
</xsl:text>
</xsl:template>
<xsl:template match="key">
<xsl:param name="indent" select="0"/>
<xsl:call-template name="doIndent">
<xsl:with-param name="indent" select="$indent"/>
</xsl:call-template>
<xsl:text>"</xsl:text>
<xsl:value-of select="."/>
<xsl:text>" = </xsl:text>
<xsl:apply-templates select="following-sibling::*[1]">
<xsl:with-param name="indent" select="$indent"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="array">
<xsl:param name="indent" select="0"/>
<xsl:text>(
</xsl:text>
<xsl:for-each select="*">
<xsl:call-template name="doIndent">
<xsl:with-param name="indent" select="$indent+1"/>
</xsl:call-template>
<xsl:apply-templates select=".">
<xsl:with-param name="indent" select="$indent+1"/>
</xsl:apply-templates>
</xsl:for-each>
<xsl:call-template name="doIndent">
<xsl:with-param name="indent" select="$indent"/>
</xsl:call-template>
<xsl:text>)
</xsl:text>
</xsl:template>
<xsl:template match="string">
<xsl:text>"</xsl:text>
<xsl:value-of select="."/>
<xsl:text>"
</xsl:text>
</xsl:template>
<xsl:template match="true">
<xsl:text>"true"
</xsl:text>
</xsl:template>
<xsl:template match="false">
<xsl:text>"false"
</xsl:text>
</xsl:template>
<xsl:template match="*|text()"/>
</xsl:stylesheet>
George
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service