473,624 Members | 2,232 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Value into Optional Attribute?

Hey all- I'm just astarting out, and this is what I'm running into--

given XML

<container>
<subject>
<name>John Smith</name>
<age>22</age>
</subject>
<subject>
<name>Mariko Suzuhara</name>
</subject>
</container>
How do I transform this to-

<test_group>
<subject age="22">John Smith</subject>
<subject>Mari ko Suzuhara</subject>
</test_group>

Such that the Age attribute remains undeclared if it was not present in
the original.
I feel liek there should be an elegant and somple solution to this that
does not involve xsl:choose (since these blocks are actually div's with
more complex content that would be duplicated.)
I've butted my head up against online help and several books, and have
concluded (since I've run across no one asking the same question and
beign shot down) that I'm simply asking the Wrong Question, and am
probably missing something obvious. I don't think it stems from having
a Pull mentality though...

....help?

-Derik

Jun 15 '06 #1
2 1097


Re********@aol. com wrote:

<container>
<subject>
<name>John Smith</name>
<age>22</age>
</subject>
<subject>
<name>Mariko Suzuhara</name>
</subject>
</container>
How do I transform this to-

<test_group>
<subject age="22">John Smith</subject>
<subject>Mari ko Suzuhara</subject>
</test_group>

<xsl:template match="subject" >
<xsl:copy />
<xsl:apply-templates select="age" />
<xsl:apply-templates select="name" />
</xsl:copy>
</xsl:template>

<xsl:template match="age">
<xsl:attribut e name="age"><xsl :value-of select="." /></xsl:attribute>
</xsl:template>

<xsl:template match="name">
<xsl:value-of select="." />
</xsl:template>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 15 '06 #2
Martin Honnen wrote:
<xsl:template match="age">
<xsl:attribut e name="age"><xsl :value-of select="." /></xsl:attribute>
</xsl:template>


....

*smacks forehead*

thank you. ;-)

-Derik

Jun 15 '06 #3

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

Similar topics

0
1472
by: Andrew Lord | last post by:
XML-Schema: Attribute Value dependent rules? As far as I can tell XML-Schema does not permit the sepcification of rules that only apply if an attribute has a certain value. For example, in the document below, attribute RemoteServer must be present and non-null if attribute LocalMachine is false, but need not be present if it is true. <Configuration> <Registry LocalMachine="false" RemoteServer="\\SERVER1" RootKey="HKEY_LOCAL_MACHINE"...
4
2931
by: Lénaïc Huard | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, I've some namespace problems when defining default values for attributes. My problem seems to come from the fact that the attributes are defined in a different namespace from the element.
4
24430
by: Randell D. | last post by:
Folks, I have a form (called FORM1) - In my INPUT submit tag, I have an onClick event that I have successfully tested/used to display the value of a TEXT box using the following function (called via an onClick event) <script type="text/javascript"> function performPrePostChecks() { // myName being an iput text box
12
4890
by: Anna | last post by:
Hi all, I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try.... in case you should see it later I apologize for posting the same question twice! Here it is: I am having problems reading the value of a text Node. I think it has to do with the fact that the text is in a <span> tag. I have a table and in each <td> I have text + a checkbox. I want to retreive the text next to the...
16
4056
by: ad | last post by:
Does C#2.0 support optional parameters like VB.NET: Function MyFunction(Optional ByVal isCenter As Boolean = False)
7
5391
by: stephan querengaesser | last post by:
hi ng, i try to invoke a webservice-method with an filter-object, that contains value types. if i don´t want to filter the return value of the method, i have to pass a new instance of the filter-object without setting any properties. but the value type-properties can´t be null and the filter is set to 0 (int) or false (bool). therefore i did implement the propertySpecified-pattern like this:
3
1892
by: LJ | last post by:
I am trying to define two xml attribute in my xsd so that they are mutual exclusive and one of them is required. For example, if I have two attributes, they are either <xsd:attribute name="p" type="xsd:string" use="required" /> <xsd:attribute name="c" type="xsd:string" use="optional" /> or <xsd:attribute name="p" type="xsd:string" use="optional" />
8
2142
by: Alan J. Flavell | last post by:
What I was trying to do: to offer a default stylesheet, plus another small stylesheet which can be applied additionally to the default one. Preferably, the optional stylesheet should be initially in effect, but the user should be able to turn it off. My reading of the HTML4 spec (which is where this seems to be documented, though I reckon it's on-topic for this group): it seems to me that what I want, in the terms described there, is...
0
1509
by: grace123 | last post by:
hi all, I have xml schema which is dataset type. there are following parts: --------------------------- <xs:element name="Receipt"> <xs:complexType> <xs:sequence> <xs:element name="Header"> <xs:complexType><xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="AlignContent" type="xs:string" use="optional" default="Left"/> <xs:attribute name="Italic" type="xs:boolean" use="optional" default="false"/> <xs:attribute name="Bold"...
3
13657
by: binder | last post by:
I am designing a new table with a few columns that may or may not have a value on each row that is inserted. What issues determine whether to allow a NULL value to be inserted for that column or define a default value to be used? I want to think through the repercussions of this decision before I get into production.
0
8681
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7170
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.