473,378 Members | 1,067 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Convert an attribute into an element

Short version of question ...

An xml file contains the following line ...

<input type="label" text="fasdfad" css_tag="h1" />

The task is to convert it into

<h1>fasdfad</h1>

But to do the conversion in such a way that the possible values for
css_tag do not have to be enumerated in the xsl file.

Something like :

<xsl:template match="input">
<xsl:choose>
<xsl:when test="@type='label'">
<<xsl:value-of select="@css_tag"/>>
<xsl:value-of select="@text"/>
<<xsl:value-of select="@css_tag"/>/>
</xsl:when>
</xsl:choose>
</xsl:template>

This however, isn't well formated XML.

The enumerated solution goes something like :

xsl:template match="input">
<xsl:choose>
<xsl:when test="@type='label'">

<xsl:when test="@css_tag='h1'">
<h1><xsl:value-of select="@text"/></h1>
</xsl:when>

<xsl:when test="@css_tag='h2'">
<h2><xsl:value-of select="@text"/></h2>
</xsl:when>

</xsl:when>
</xsl:choose>
</xsl:template>
Any ideas?
Jul 20 '05 #1
1 1604
GIMME <gi*******************@yahoo.com> wrote:
Short version of question ...

An xml file contains the following line ...

<input type="label" text="fasdfad" css_tag="h1" />

The task is to convert it into

<h1>fasdfad</h1>
I would do something like

start () { # Usage: start tag att=value ...
declare "$@" # sets up 'type', 'text', 'css_tag' variables
if [[ $1 == input && $type == label ]]; then
echo "<$css_tag>$text</$css_tag>"
fi
}

x='<input type="label" text="fasdfad" css_tag="h1" />'
xml -s start "$x"

Ref:
http://freshmeat.net/projects/bashdiff/
http://home.eol.ca/~parkw/index.html#xml
help xml

It's patch to Bash shell with, in this case, an interface to Expat XML
parser. It's main advantage is that you use shell scripting (something
you know already) to cut/splice XML document. XSL applies to only XML,
whereas shell applies to everything that you do on your machine.

But to do the conversion in such a way that the possible values for
css_tag do not have to be enumerated in the xsl file.

Something like :

<xsl:template match="input">
<xsl:choose>
<xsl:when test="@type='label'">
<<xsl:value-of select="@css_tag"/>>
<xsl:value-of select="@text"/>
<<xsl:value-of select="@css_tag"/>/>
</xsl:when>
</xsl:choose>
</xsl:template>

This however, isn't well formated XML.

The enumerated solution goes something like :

xsl:template match="input">
<xsl:choose>
<xsl:when test="@type='label'">

<xsl:when test="@css_tag='h1'">
<h1><xsl:value-of select="@text"/></h1>
</xsl:when>

<xsl:when test="@css_tag='h2'">
<h2><xsl:value-of select="@text"/></h2>
</xsl:when>

</xsl:when>
</xsl:choose>
</xsl:template>
Any ideas?


--
William Park <op**********@yahoo.ca>
Open Geometry Consulting, Toronto, Canada
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Moonbeam66 | last post by:
I'm looking to convert an element name to an attribute name, where the element name is user-defined. For example <accountNumber>12345678</accountNumber>. I want to convert this to <userTag...
5
by: jk | last post by:
I'm having trouble converting a datatable into xml, with resonse.write to aspx. I'm basically converting vb code that saved a recordset into a stream into c#, but the format is wrong. I've tried...
1
by: Tod Johnson | last post by:
Hello all, Can't figure it out. :( Assume that we have 2 XML document: Document1 (source): <elements> <elementA attribute1="value1" attribute2="value2" ... /> <elementA attribute1="value1"...
6
by: Eric | last post by:
.... my eternal gratitude!!! :p Here is the problem. A sample of my original VB6 code : '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public...
1
by: arnold | last post by:
Hi, I've been knocking my head against the wall trying to create an XSL transform to perform "normalizations" of a set of XML files that have a common structure. % XML file before transform
1
by: Jorge | last post by:
I want to convert this xml to pdf using cocoon <?xml version="1.0" encoding="ISO-8859-1" ?> <document> <header> <title>Pagina</title> </header> <body> <h1>Link dei siti pił visitati da...
5
by: Norsoft | last post by:
How can I convert an existing schema to an xml document. I have a series of schema documents that validate xml documents that describe metadata. Normally the metadata is first defined in a database,...
27
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set...
3
by: Eric Lilja | last post by:
Hello, this is an xml-file with a nested DTD. It validates, test-1- with-dtd.xml: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE persons > <persons> <person name="Eric Lilja" /> </persons>
1
by: ismailc | last post by:
Hi, I don't know xslt - i just need a modification done to existing xslt file. At the moment the page has 2 radio buttons with a submit button, which exeutes the code dependant on the radio...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.