Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL and paragraph editing 1

Status
Not open for further replies.

Gaelle

Programmer
Jun 20, 2001
62
FR
Hello !
I'm french so please don't mind my poor english !
I have a xml structure which build a document made of title, blocs and paragraphs.
I manage to display my datas with an XSL file, but what I'd like to do now is shifting my paragraphs like this :
TITLE
Part 1
Part 1.1
paragraph
paragraph
Part 1.2
Part 2
Because I only manage to get
TITLE
Part 1
Part 1.1
paragraph
paragraph
Part 1.2
Part 2

My XSL page is looping over my document structure like this :
<xsl:for-each select=&quot;document//bloc&quot;>
<xsl:value-of select=&quot;titre&quot;/><br/>
<xsl:for-each select=&quot;.[paragraphe]&quot;>
... and so on

What I think I should do is making a kind of function that takes the level of a title or a bloc, and puts &quot;     &quot; ahead, but I have tried a JavaScript function and I can't have it working.

Can someone help me, please !!!
Thanks,
Gaelle.
 
Hello,
There is a property called margin-left in CSS and you could use it as &quot;margin-left: 5&quot; in pixels or &quot;margin-left: 5%&quot;.
Also I would recommend using applying templates instead of for-each.

Let have the following xml file docum.xml
<?xml version=&quot;1.0&quot;?>
<document>
<title>Big Title </title>
<part id=&quot;1&quot;> Part 1
<subpart id=&quot;1&quot;> Part 1.1
<para>Paragraph a</para>
<para>Paragraph b</para>
<para>Paragraph c</para>
</subpart>
<subpart id=&quot;2&quot;> Part 1.2
<para>Paragraph 1</para>
<para>Paragraph 2</para>
<para>Paragraph 3</para>
</subpart>
</part>
<part id=&quot;2&quot;> Part 2
<para>Paragraph DDD1</para>
<para>Paragraph DDD2</para>
<para>Paragraph DDD3</para>
</part>
</document>

Let have the following xsl file docum.xsl:
<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot; <xsl:template match=&quot;/&quot;>
<html>
<body><xsl:value-of select=&quot;//title/text()&quot;/><br/>
<xsl:apply-templates select=&quot;//part&quot;/>
</body>
</html>
</xsl:template>
<xsl:template match=&quot;part&quot;>
<span style=&quot;margin-left: 5&quot;><xsl:value-of select=&quot;./text()&quot;/></span><br/>
<xsl:apply-templates select=&quot;./subpart&quot;/>
<xsl:apply-templates select=&quot;./para&quot;/>
</xsl:template>
<xsl:template match=&quot;subpart&quot;>
<span style=&quot;margin-left: 10&quot;><xsl:value-of select=&quot;./text()&quot;/></span><br/>
<xsl:apply-templates select=&quot;./para&quot;/>
</xsl:template>
<xsl:template match=&quot;para&quot;>
<span style=&quot;margin-left: 15&quot;><xsl:value-of select=&quot;./text()&quot;/></span><br/>
</xsl:template>
</xsl:stylesheet>

The result will be visible through server-side processing (an asp file for example - docum.asp)

<%
'Load the XML
set oXmlDoc = Server.CreateObject(&quot;MSXML2.DOMdocument&quot;)
oXmlDoc.async = false
oXmLDoc.load(Server.MapPath(&quot;docum.xml&quot;))

'Load the XSL
set oXslDoc = Server.CreateObject(&quot;MSXML2.DOMdocument&quot;)
oXslDoc.async = false
oXslDoc.load(Server.MapPath(&quot;docum.xsl&quot;))

'Transform the file
Response.Write(oXmlDoc.transformNode(oXslDoc))
%>

Hope this helps.
D.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top