0

I am using the XML->XHTL conversion for printing a model based window. What I do is to convert my model into a well formed xml. And then applying xsl to it.

A few attributes in my model have large text value. Occasionally this text may contain, "<" and ">". Whenever such text appears, the text between "<" and ">" is skipped. For example, if my text is "This <item name> belongs to me." The output I get is "This belongs to me." <item name> is skipped. It looks like these characters in the attribute's value are also identified as the beginning and end of xml tags. They get converted to &lt; and &gt;. And so the value is not printed.

Can anyone please tell me, how can i retain the angular brackets in the attribute's value in output as well? Any help is greatly appreciated.

Thanks, Sahitya

P.S.-I am a newbie to xml handling and xsl as well.

XML with the CData section: "<descriptionText><![CDATA[This <item name> belongs to me.]]></descriptionText>"

XSL excerpt: <tr><td><xsl:value-of select="descriptionText" disable-output-escaping="yes"/></td></tr>

expectedOutput: This <item name> belongs to me.

ActualOutput: This belongs to me.

EDIT:

For implementing the print functionality at the application level, I am using the APIs of WebFrameLoadDelegate and NSPrintOperation. Once the webview is created successfully, the delegate API,

- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame;

of the printer class, is called. Please see the implementation of this API below:

- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
    NSPrintInfo *pi = [NSPrintInfo sharedPrintInfo];
    if ([NSPrintInfo defaultPrinter])
    {
        [pi setPrinter:[NSPrintInfo defaultPrinter]]; 
    }
    [pi setTopMargin:5.0];
    [pi setLeftMargin:5.0];
    [pi setBottomMargin:10.0];
    [pi setRightMargin:5.0];
    [pi setHorizontalPagination:NSFitPagination];
    [pi setVerticalPagination:NSFitPagination];
    [pi setVerticallyCentered:YES];
    [pi setHorizontallyCentered:YES];
    [[self.webView preferences] setAutosaves: NO];
    [[self.webView preferences] setShouldPrintBackgrounds:YES];
    NSPrintOperation *printOperation = [[[self.webView mainFrame] frameView] printOperationWithPrintInfo:pi];
    [printOperation runOperationModalForWindow:self.window delegate:self.delegate didRunSelector:self.callbackSelector contextInfo:nil];
}
4

2 回答 2

1

如果你

  1. 将包含<&in的文本包装CDATA在 XML 输入中
  2. 不要使用_disable-output-escaping

然后的输出This <item name> belongs to me将是This &lt;item name&gt; belongs to me,浏览器将正确显示为This <item name> belongs to me.

如果打开 disable-output-escaping则生成的 HTML 将为This <item name> belongs to me,并且浏览器会认为<item name>是未定义的 HTML 标记并跳过它,如您所描述的。

编辑

这是一个功能齐全的示例:

simple.xml(输入)

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="simple.xslt"?>
<simple>
    <![CDATA[This <item name> belongs to me.]]>
</simple>

简单的.xslt

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <xsl:value-of select="."/>
    </xsl:template>
</xsl:stylesheet>

输出(在浏览器中打开 xml 时)

This <item name> belongs to me.
于 2012-07-05T07:59:09.613 回答
0

HTML 文本中不能有尖括号,它们需要转义为 > 和 <。我希望 CDATA 部分解决了转换为 HTML 的问题,但是当您查看 HTML 时,浏览器会忽略它不理解的标签。

于 2012-07-02T13:51:38.643 回答