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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xml line numbering issue

Status
Not open for further replies.

NirvanaX

Programmer
Apr 27, 2005
2
US
i have to convert some xml information to text. The critical issue i have is that my template instantiation requires me to add extra text information to the text file. For example suppose my xml document looks like this:
<Dir Path="..">
<File>xyz.xml</File>
</Dir>
<Dir Path="C:\Temp">
<Wildcard>*.xml</Wildcard>
</Dir>

and i need to check for this node which i do using <xsl:template match="Dir"> and after the XSL processor instantiates this template i need to write text to my basic text file like this

1. Type="Dir"
2. Path="C:\Temp">
3. File=xyz.xml
4. EOD ( means end of dir )
5. Type="Dir"
6. Path="C:\Temp">
7. Wildcard= *.xml
8. EOD ( means end of dir )

when i wrote a transformation using xsl:number or xsl:value-of select="position()" and used count for any level, it counts based on nodes so it says

1. Type="Dir"
1. Path="C:\Temp">
1. File=xyz.xml
1. EOD ( means end of dir )

for the first template match and the next template match would give:
2. Type="Dir"
2. Path="C:\Temp">
2. Wildcard=*.xml
2. EOD ( means end of dir )

My question is how do i get the 1.2.3.4 format numbering format for the added text for each template? i use <xsl:text> to add text for each node type. Any inputs on this is very much appreciated!

Thanks
 
How about this:
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
  <xsl:output method="text"/>
  <xsl:template match="/">
    <xsl:apply-templates select="*/Dir"/>
  </xsl:template>
  <xsl:template match="Dir">
    <xsl:value-of select="concat((position()*4)-3, '. Type=&#34;Dir&#34;&#010;')"/>
    <xsl:value-of select="concat((position()*4)-2, '. Path=&#34;', @Path, '&#34;&#010;')"/>
    <xsl:value-of select="concat((position()*4)-1, '. ', name(*), '=', *, '&#010;')"/>
    <xsl:value-of select="concat(position()*4, '. EOD&#010;')"/>
  </xsl:template>
</xsl:stylesheet>

Jon

"There are 10 types of people in the world... those who understand binary and those who don't.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top