问题: 已解决,我能够生成一个脚本,该脚本将通过我的 XHTML 列表并生成 XML 输出。
问题是:当我有一个有序列表时,XSLT 应该是什么样子?
谢谢@Sbof
我需要生成以下 XML:
<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/ul">
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/Character Style 1">
<Content>abc</Content>
<Br/>
<Content>xyz</Content>
<Br/>
<Content>abc</Content>
<Br/>
<Content>xyzabc</Content>
<Br/>
</CharacterStyleRange>
</ParagraphStyleRange>
<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/ol level 1">
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/Character Style 1">
<Content>xyz</Content>
<Br/>
</CharacterStyleRange>
</ParagraphStyleRange>
<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/ol level 2">
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/Character Style 1">
<Content>abc</Content>
<Br/>
</CharacterStyleRange>
</ParagraphStyleRange>
我有看起来像这样的 XHTML(内容不同,但做同样的事情):
<?xml version="1.0" encoding="utf-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<ol>
<li>abc</li>
<li>xyz</li>
<li>abc</li>
<li>xyzabc</li>
<li>xyz<ol>
<li>abc</li>
</ol>
</li>
<li>xyzxyz</li>
<li>abc</li>
<ol>
<li>xyz</li>
</ol>
<li>next level</li>
</ol>
</body>
</html>
这是横穿 XHTML 的 XSLT 片段:
<xsl:template match="xhtml:ol/xhtml:li[not(*)]">
<xsl:call-template name="para-style-range">
<xsl:with-param name="style-name">article%3aol Level 1</xsl:with-param>
</xsl:call-template>
<xsl:if test ="xhtml:ol/xhtml:li[*]|
xhtml:ul/xhtml:li[*]">
<xsl:apply-templates select="xhtml:ol/xhtml:li[*]|
xhtml:ul/xhtml:li[*]" />
</xsl:if>
</xsl:template>
这是我使用脚本得到的结果:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<idPkg:Story xmlns:idPkg="http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging" DOMVersion="7.5">
<Story Self="ucb" AppliedTOCStyle="n" TrackChanges="false" StoryTitle="$ID/" AppliedNamedGrid="n">
<StoryPreference OpticalMarginAlignment="false" OpticalMarginSize="12" FrameType="TextFrameType" StoryOrientation="Horizontal" StoryDirection="LeftToRightDirection"/>
<InCopyExportOption IncludeGraphicProxies="true" IncludeAllResources="false"/>
<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/ul">
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/Character Style 1">
<Content>abc</Content>
<Br/>
<Content>xyz</Content>
<Br/>
<Content>abc</Content>
<Br/>
<Content>xyzabc</Content>
<Br/>
</CharacterStyleRange>
</ParagraphStyleRange>
<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/ol level 1">
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/Character Style 1">
<Content>xyz</Content>
<Br/>
</CharacterStyleRange>
</ParagraphStyleRange>
<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/ol level 2">
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/Character Style 1">
<Content>abc</Content>
<Br/>
</CharacterStyleRange>
</ParagraphStyleRange>
<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/ol level 1">
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/Character Style 1">
<Content>xyzxyz</Content>
<Br/>
<Content>abc</Content>
<Br/>
</CharacterStyleRange>
</ParagraphStyleRange>
<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/ol level 3">
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/Character Style 1">
<Content>xyz</Content>
<Br/>
</CharacterStyleRange>
</ParagraphStyleRange>
<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/ol level 1">
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/Character Style 1">
<Content>next level</Content>
<Br/>
</CharacterStyleRange>
</ParagraphStyleRange>
</Story>
</idPkg:Story>
XSLT 截取段落的属性值:
<xsl:template name="para-style-range">
<!-- The name of the paragraph style in InDesign -->
<xsl:param name="style-name"/>
<xsl:param name ="isTable" />
<!-- A string of text that will precede the paragraph's actual content (ex: 'by ')-->
<xsl:param name="prefix-content" select="''"/>
<ParagraphStyleRange>
<xsl:attribute name="AppliedParagraphStyle">
<xsl:value-of select="concat('ParagraphStyle/', $style-name)"/>
</xsl:attribute>
<xsl:if test="$prefix-content != ''">
<CharacterStyleRange>
<Content><xsl:value-of select="$prefix-content"/></Content>
</CharacterStyleRange>
</xsl:if>
<xsl:apply-templates select="text()|*" mode="character-style-range"/>
<xsl:choose>
<xsl:when test ="$isTable = 'true'">
<!--Dont do any thing here-->
</xsl:when>
<xsl:otherwise>
<Br/>
</xsl:otherwise>
</xsl:choose>
</ParagraphStyleRange>
</xsl:template>
让我知道我是否可以提供更多脚本来帮助那些仍然对代码感到困惑或需要帮助弄清楚它的人。