|
Hi Shakhtyor,
Thanks for letting me know about this Book!
Thanks,
Rahi
If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
Hi,
I am new to XSL and I was hoping someone could help me with a problem I am having.
I have an Input.xml file to which I want to apply a xsl stylesheet Style.xsl. I also have a Template.xml file which I want to use as the base for the output file.
At the moment, here is what I have:
<!-- Input.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<InputRoot>
<elem name="a" AttName='11'></elem>
<elem name="b" AttName='22'></elem>
<elem name="c" AttName='33'></elem>
<elem name="d" AttName='44'></elem>
<elem name="e" AttName='55'></elem>
<elem name="f" AttName='66'></elem>
</InputRoot>
<!-- Template.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<TemplateRoot>
<elem name="a" AttName='Ones'></elem>
<elem name="b" AttName='Twos'></elem>
<elem name="c" AttName='Threes'></elem>
<elem name="d" AttName='Fours'></elem>
<elem name="e" AttName='Fives'></elem>
<elem name="f" AttName='Sixes'></elem>
</TemplateRoot>
<!-- Style.xsl -->
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:variable name="Template" select="document('Template.xml')"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="elem">
<xsl:variable name="iden" select="@name"/>
<xsl:variable name="attrVal" select="@AttName"/>
<xsl:variable name="newAttrName" select="$Template/TemplateRoot/elem[@name =$iden]/@AttName"/>
<xsl:element name="elem">
<xsl:attribute name="name">
<xsl:value-of select="@name"/>
</xsl:attribute>
<xsl:attribute name="{$newAttrName}">
<xsl:value-of select="$attrVal" />
</xsl:attribute>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
<!-- Output.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<InputRoot>
<elem name="a" Ones="11"/>
<elem name="b" Twos="22"/>
<elem name="c" Threes="33"/>
<elem name="d" Fours="44"/>
<elem name="e" Fives="55"/>
<elem name="f" Sixes="66"/>
</InputRoot>
I seem to be doing this backwards, here is what I want
<!-- Desired Output.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<TemplateRoot>
<elem name="a" Ones="11"/>
<elem name="b" Twos="22"/>
<elem name="c" Threes="33"/>
<elem name="d" Fours="44"/>
<elem name="e" Fives="55"/>
<elem name="f" Sixes="66"/>
</TemplateRoot>
Any help would be greatly appreciated
-----------------
Genaro
|
|
|
|
|
picazo wrote: I have an Input.xml file to which I want to apply a xsl stylesheet Style.xsl. I also have a Template.xml file which I want to use as the base for the output file.
So you are trying to use 2 XML files in the XSLT right? There may be support for that in XSLT 2.0 I am not sure. Even if there is there may not be an engine that supports it yet, I don't know. However:
picazo wrote: I also have a Template.xml file which I want to use as the base for the output
That is what the XSLT is for so you may just be over complicating your solution. You should only need the XSLT file and a single XML input file.
led mike
|
|
|
|
|
picazo wrote:
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
This code is really your problem. You should try matching differently. Instead of doing this, try replacing it with:
<xsl:template match="/">
<TemplateRoot>
<xsl:for-each select="InputRoot/elem">
<xsl:apply-templates select="."/>
</xsl:for-each>
</TemplateRoot>
</xsl:template>
The code may not be exactly correct because I was too lazy to test it. I think it's a neat idea to mix two XML files, but it depends on your requirements. In most cases, you would want to adjust the XSL instead of having a template XML file outside, like led mike suggested.
|
|
|
|
|
Hi guys,
I've only ever worked with XML, never really designed, so I'm looking for a little advice. I need to design four request message types (and corresponding replies, but that later). I would like to use a standard enclosing document, with a message type attribute or element that then defines how the recipient must treat the rest of the message. I don't know where to start, what guidelines to use for structure, where attributes and where elements etc. Any advice and tips will be appreciated.
|
|
|
|
|
Try searching for "XML Schema Best Practices".
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Brady Kelly wrote: I don't know where to start
Representing data in XML is not that far removed from traditional programming. Design your data just as you would in a C structure. Now that structure can be mostly mirrored in XML.
Brady Kelly wrote: I would like to use a standard enclosing document, with a message type attribute or element that then defines how the recipient must treat the rest of the message
Take a look at the high level design of SOAP.
Brady Kelly wrote: where attributes and where elements etc
There is no cookbook approach. The best advice would be to NOT mix "actual data". Meaning don't put some data in text nodes and others in attributes. So if you use text nodes for data then attribute usage should be limited to Metadata usage. Conversely if you are going to have much metadata then using text nodes for the real data might make the XML more readable.
I hope that helps at least a little
led mike
|
|
|
|
|
HELP EACH OTHER TO GROW TOGETHER.
|
|
|
|
|
You should post a question or an issue if you want an answer.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Without access to the source code this is impossible (well legally anyway and depending on the setup illegally as well).
I have no idea what I just said. But my intentions were sincere.
|
|
|
|
|
I've got some data already formatted in xml format stored in a single excel cell. I want to export the formatted xml data held in this single cell as a full xml document using excel vba.
Does anyone know how to do this?
Al
|
|
|
|
|
|
Thanks George. I'll take a good look at this.
Al
|
|
|
|
|
Hey guys, I was wondering how do I change the settings of a webpage programatically if the page is using an external styles sheet (lets say styles.css).
If I would like to...lets say change the background color in the load event of the page or perhaps the button click event...right now I'm doing that in the html mode by assigning the value directly to the inline style element.
But I'll be creating external style sheets, and would like to grab the values from their programatically in code behind.
Can some one point me to the right direction??
Thanks
~TINA
|
|
|
|
|
i don't really understand u, but you can change "styles" using javascript, another way its you read first the css file, and then apply your external styles.
|
|
|
|
|
If you are talking about toggling between to different style sets, for example, the easiest way I have found is to change the "class" attribute via javascript. Of course, you should have already created these "classes" in an internal or external style sheet(s).
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Hello!
Ive got a configfile looking something like this:
name="test"
host="164.9.193.32"
protocol="1.2.3.4" port="89"
application="c:\test\test.exe"
useDefaultCredentials="false"
Im trying to update the config with this:
XmlNode node = null;
XmlNode attrNode = null;
for (int i = 0; i < nodeList.Count; i++)
{
node = nodeList.Item(i);
attrNode = node.Attributes.GetNamedItem("host", "");
attrNode.Value = NewHostValue;
attrNode = node.Attributes.GetNamedItem("port", "");
attrNode.Value = NewPortValue;
attrNode = node.Attributes.GetNamedItem("protocol", "");
attrNode.Value = NewProtocolValue;
attrNode = node.Attributes.GetNamedItem("application", "");
attrNode.Value = NewApplicationValue;
}
But after this is run the data comes out in a single row without newlines.
<assembly name="test" host="164.9.193.32" protocol="1.2.3.4" port="89" application="c:\test\test.exe" useDefaultCredentials="false" />
Im having a hard time coming up with a good way to keep the old look, anyone got an idea?
/regards
-- modified at 9:16 Friday 12th January, 2007
|
|
|
|
|
Disregard that. You might have to use an XSL transform to introduce linebreaks.
led mike
|
|
|
|
|
okay, what would that look like?
|
|
|
|
|
Hi,
Is it possible to generate a working code with a working logic in it from a xml file. If yes then how?? I have to build a class with methods and attributes from XML on some machine. So machine updates the code in run time and then receives objects from various sources and do some algorithm on them??? Any idea??
Regards
Ash
|
|
|
|
|
For my XML parser code
IXMLDOMNode* iNode = NULL;
IXMLDOMNodeList* List = NULL;
iRooterElm->get_childNodes( &List );
long Amount=0;
List->get_length( &Amount );
for( int i = 0; i <=Amount; i++ )
{
List->get_item( i, &iNode );
DisplayChildren( (IXMLDOMElement*)iNode ); // This is where the parsing is done
}
When the child element has no siblings ,the call to DisplayChildren( (IXMLDOMElement*)iNode ); wroks fine and parses the element into tags and text.
But when the child element has siblings ,List->get_length( &Amount ) returns a wrong length and returns amount as 1.ie it doesnt count all siblings ..so my call to DisplayChildren
happens only once and only first child is parsed ..other siblings are simply left out
lkrishn
|
|
|
|
|
I am fairly new to the idea of web services and I was just told by a programmer that they send the pre-formatted XML to the web service URL. I am curious what it is that would require that they send it in that way and how they do that.
Cleako
|
|
|
|
|
Hi guys
question #1
I have a web sites that sells computer parts and accessories, and I design a webservice for my products to distrubute the parts list.
it is under ;
http://cemalpcstore.com/webservice.aspx?wsdl
could you please test and see if it is working, I just learn how to make one I am still studying on consuming xml web services
anyway, please let me know what you think (regarding speed, and if contents are sufficient) no password or username required.
question #2
how should I let my clients know what are fields are that they should be expecting from response object??
thanks
Cemal
ps.as you can see I am newbie to the subject.
|
|
|
|
|
How to parse an XML and display the nested/nonnested nodes in it
|
|
|
|
|
Hello again...
I really appreciate the help you folks are giving me.
I have an XmlElement from a validated XmlDocument. I can't find a way to retrieve the element's expected attributes from its SchemaInfo property.
I was hoping this property would tell me all about how this element is described in the schema (i.e. what child elements are valid on it, what attributes are valid on it, etc.).
Am I barking up the wrong tree? I simply need a list of ALL valid attributes on the element.
BTW, XmlSchemaValidator looked promising, but it always returns null from the GetExpectedAttributes method when the context is the element that was validated. It retrieves the attributes for any of the validated element's CHILD ELEMENTS but can't seem to retrive them for the validated element...
Thoughts?
Thanks so much!
Ian
|
|
|
|