|
I have an .xml file like this:
<group>
<line> some text</line>
<line> some text</line>
<line/>
<line> some text</line>
<line> some text</line>
</group>
and I want to transform it to a table like:
some text | some text | | some text | some text |
but the empty raw never appears. Empty tags are ignored? How can I preserve them?
|
|
|
|
|
Where is your transform?
This should do it.
<xsl:for-each select="group/item">
<tr><td><xsl:value-of select="."/></td></tr>
</xsl:for-each>
|
|
|
|
|
this is my transoform (part of the style sheet)
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="80" valign="top"></td>
<td width="45" align="right" class="number"></td>
<td width="30" align="center"></td>
<td class="PoetryTitle"><xsl:value-of select="poem/stave/title"/></td>
<td width="10"></td>
</tr>
<tr>
<td width="80" valign="top"></td>
<td width="45" align="right" class="number"></td>
<td width="30" align="center"></td>
<td class="PoetrySubtitle"><xsl:value-of select="poem/stave/subtitle"/></td>
<td width="10"></td>
</tr>
<tr>
<td width="80" valign="top"></td>
<td width="45" align="right" class="number"></td>
<td width="30" align="center"></td>
<td class="EmptyLine">.</td>
<td width="10"></td>
</tr>
<xsl:for-each select="poem/stave">
<tr>
<td width="80" valign="top"></td>
<td width="45" align="right" class="number"><xsl:value-of select="number"/></td>
<td width="30" align="center"></td>
<td ><xsl:value-of select="verse"/></td>
<td width="10"></td>
</tr>
<tr>
<td width="80" valign="top"></td>
<td width="45" align="right" class="number"></td>
<td width="30" align="center"></td>
<td class="EmptyLine"><xsl:value-of select="emptyline"/></td>
<td width="10"></td>
</tr>
<tr>
<td width="80" valign="top"></td>
<td width="45" align="right" class="number"></td>
<td width="30" align="center"></td>
<td class="PoetryComments"><xsl:value-of select="notes"/></td>
<td width="10"></td>
</tr>
</xsl:for-each>
</table>
|
|
|
|
|
<xsl:value-of select="."/>
why the "."?
my workaround is: <emptyline>.<emptyline> and the color of the . is set to the background, so it looks like an empty line.
another problem is that I have text formated like this:
<line>first line</line>
<line> second line</line>
<line>third line</line>
but it appears like this (after transformation)
first line
second line
third line
"& nbsp ;" is rejected as invalid so I cannot use it for formatting.
|
|
|
|
|
This should work:
<xsl:text disable-output-escaping="yes"> </xsl:text>
Edward
|
|
|
|
|
Hi,
I need to convert some .xml files into tables so that they can be viewed in a web browser.
Is there a way to do that without to need learning XML/XSLT
If now what is the easiest and quickest way to do that? (I doubt I'll need to do anything similar again)
Is it possible to use XML/XSLT to generate these tables as a part of .html page created as a template with Dreamweaver.
Thank you! I've got scared by the size of these books about XML
|
|
|
|
|
XSLT for Dummies, learn to write XML transforms without reading.
Now wouldn't that be great.
You're going to have to get over it and learn something.
|
|
|
|
|
thanx
Any easy online sources to get me running in half a day I don't have much time to spend on that, which is the main problem.
|
|
|
|
|
You can do somthing like this:
dim nodes as xmlnodelist = xmlDoc.selectnodes("//root/whatever")
dim node as xmlnode
for each node in nodes
response.write("<div class=""" & node.name & """>" & node.innerText & "</div>");
next
This is kinda kludgy, you really want to use an xslt file But doing this you could create tables by making div tables with the sytlesheet.
Check this place out for info on XSLT:
XSLT Tutorial
|
|
|
|
|
I already read the XSLT tutorial it doesn't seem that hard as I thought. I have actually done almost all I wanted .
The only problem now is that I currently support XML compatible browsers only.
BTW. I've checked your article here and there is no source code attached to it.
Regards
|
|
|
|
|
Thanks for telling me, I fixed the link...
|
|
|
|
|
Hi,
I'm trying to convert the value of an element, into a string of a certain amount of characters - right justified.
e.g. <abc>123456</abc> into a 10-character string - " 123456"
How would this be done, if possible?
|
|
|
|
|
not easy to do in xslt - here is the "pure" way (you could just embed some c# code in the xslt)
xml source document:
<br />
<document><br />
<abc>1234</abc><br />
<abc>234234</abc><br />
<abc>21321</abc><br />
<abc>91243149384</abc><br />
</document><br />
xslt document:
<br />
<?xml version="1.0" encoding="UTF-8" ?><br />
<xsl:stylesheet <br />
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"<br />
version="1.0"><br />
<br />
<xsl:output method="xml" <br />
media-type="text/xml" <br />
indent="yes"<br />
encoding="UTF-8"/><br />
<br />
<xsl:template name="document"><br />
<xsl:apply-templates select="abc" /><br />
</xsl:template><br />
<br />
<xsl:template name="abc"><br />
<xsl:call-template name="padstring"><br />
<xsl:with-param name="times" select="10 - string-length(text())" /><br />
<xsl:with-param name="string"><xsl:value-of select="text()" /></xsl:with-param><br />
</xsl:call-template> <br />
</xsl:template><br />
<br />
<xsl:template name="padstring"><br />
<xsl:param name="current">1</xsl:param><br />
<xsl:param name="times" /><br />
<xsl:param name="string" /><br />
<xsl:param name="paddingchar"> </xsl:param><br />
<br />
<xsl:if test="$times > 0)><br />
<xsl:value-of select="$paddingchar" /><br />
</xsl:if><br />
<br />
<xsl:if test="not($times < $current) and $current != $times"><br />
<xsl:call-template name="padstring"><br />
<xsl:with-param name="current" select="$current + 1" /><br />
<xsl:with-param name="times" select="$times" /><br />
<xsl:with-param name="string" select="$string" /><br />
<xsl:with-param name="paddingchar" select="$paddingchar" /><br />
</xsl:call-template><br />
</xsl:if><br />
</xsl:template><br />
<br />
</xsl:stylesheet><br />
should work...
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
I'm a newbie,so please bear I have asp.net page which gets input from the user . I had to convert that input to xml and send it to the 3rd party database and get the output in xml . I convert that xml to html using XSL file by using Load and Transform methods in .NET
My XSL is similar to this .
This is simple part which is done .
The tricky part is After i display i do want to provide links to the elements displayed . I want to provide a link for these elements
so that when the user hits the link, the link spawn's another search and returns the result .I Was wondering how would i do that . Do i have to call etxernal objects from XSL to call the same ASPX page which i used previously to generate the original response.
Any thoughts appreciated...
|
|
|
|
|
One way would be to use an xml data island and some javascript to search and return the results while on the client side. Using a postback mechanism you could also post-back to your aspx and display the requested results.
|
|
|
|
|
Mark, I was thinking almost in the same lines as you mentioned to use javascript . But my search is actually not to an xml file its actually to a 3rd party xml database(xml webservice) . so i was thinking actually
to pass the values from XSL file to the aspx page and get the results .
|
|
|
|
|
Depending on the size of the data returned and your requirements you could still use the xml data island. As the page is initially rendered stuff the xml data island with the return from your database query. Then it is all client side javascript. Faster responses for the user but of course it only works for IE.
|
|
|
|
|
Params to the XSL file
Check this out I just posted it [Post]
You can send a param to the XSL and have it print it out as a link.
|
|
|
|
|
Does anybody know how to fill the fields of IE's web page
from within VB or C++ ? What if the page is secure? Of
course, there is no problem to fill all the fields by
hand. The question is how to do it automatically, by
running .exe or .dll.
|
|
|
|
|
Take a look at IHTMLDocument and IHTMLElement)interfaces. In general you'd need to get a hold of html document, then get and html elemnt that you are interseted in (using probaly one of getElement.. methods) and then change it.
Edward
|
|
|
|
|
I'm needing to convert a supplied XML file into a text file to submit to a lodgement system.
<Extraction>
<BBRequest>
<BBB>Greg</BBB>
<ABC>Y</ABC>
<GKS>5000</GKS>
<POAddress>
<ABH>5 Rode rd</ABH>
<ABI>Hawthorne</ABI>
<ABJ>Brisbane</ABJ>
<ABK>4052</ABK>
</POAddress>
<POD>10</POD>
</BBRequest>
<ITLRequest>
<AWR>IV</AWR>
<ABB>2003</ABB>
<YYT>05072003</YYT>
<CZK>N</CZK>
<ABE>MRS</ABE>
<ABF>STEWART</ABF>
<ABG>JOY</ABG>
<BBB>LYNETTEV</BBB>
<POAddress>
<ABH>20 Waterworks Rd</ABH>
<AME>ALFREDTON</AME>
<AMF>VIC</AMF>
<APE>3350</APE>
</POAddress>
<HomeAddress>
<ABK>20 LAUDERDALE AVENUE</ABK>
<AXQ>ALFREDTON</AXQ>
<AXR>VIC</AXR>
<APH>3350</APH>
</HomeAddress>
<ACG>N</ACG>
<AMB>300</AMB>
<ANJ>C</ANJ>
<ABP>cleaner</ABP>
<ABO>9111</ABO>
<ATY>28630</ATY>
<ATD>5913</ATD>
<GKS>5885453745</GKS>
</ITLRequest>
</Extraction>
The required text file needs each request (BBRequest and ITLRequest) on a seperate line, and to have the list number at the front. Each of the 3 Letter Nodes (e.g. GKS)has to be put in the format ^NNNVVV (Nodename and Value). Finally, the count of requests has to be at the bottom.
00001^BBBGreg^ABCY^GKS5000^POAddress^ABH5 Rode rd^ABIHawthorne^ABJBrisbane^ABK4052^POD10^ZZZ
00002^AWRIV^ABB2003^YYT05072003^CZKN^ABEMRS^ABFSTEWART^ABGJOY^BBBLYNETTEV^ABH20 Waterworks Rd^AMEALFREDTON^AMFVIC^APE3350^ABK20 LAUDERDALE AVENUE^AXQALFREDTON^AXRVIC^APH3350^ACGN^AMB300^ANJC^ABPcleaner^ABO9111^ATY28630^ATD5913^GKS5885453745^ZZZ
Count: 2
The main problem I'm having is working out how to get the three letter node name into the final document, and how to list each transaction.
Any help would be muchly appreciated.
|
|
|
|
|
something like this would work:
<xsl:template match="Extraction"><br />
<xsl:for-each select="BBRequest|ITLRequest"><br />
<br />
<xsl:for-each select="*"><br />
<br />
^<xsl:value-of select="name()" /><xsl:value-of select="text()" /><br />
<br />
<-- get any details in subitems such as POAddress and HomeAddress --><br />
<xsl:for-each select="*"><br />
^<xsl:value-of select="name()" /><xsl:value-of select="text()" /><br />
</xsl:for-each><br />
<br />
</xsl:for-each><br />
<br />
</xsl:for-each><br />
</xsl:template>
the trick is to use the name() function to get the name of the node
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
I want to POST something like this
http://xmlsearch.com/srch.asp?searchfor='test'
to the server and
the Server will respond by sending the XML data
I am using MFC and CInternetSession Class
How do i Parse the XML data ?
any suggestions and sample codes will be welcomed
Live as if your were to die tomorrow. Learn as if you were to live forever.
-Mahatma Gandhi
|
|
|
|
|
|
This might help if you are using asp . You need to create a corresponding xsl
for the xml output. Then u can use the function below in your asp page .
<%
'Load the XML
set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.load(Server.MapPath("Yourxmldoc.xml"))
'Load the XSL
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("yourxsldoc.xsl"))
Response.Write(xml.transformNode(xsl))
%>
|
|
|
|