• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to change the xml tag name using xslt

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am trying to transform this xml file-

<ES_DI_collection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ES_DI id="YYYY" abbreviated_title="Aspirin daily" style="text">
<Index>
<Section>Treatment</Section>
<Menu>Cardio/Circ Tx</Menu>
</Index>
<Instruction title="Daily Aspirin:" language="english">Aspirin has been used for many years to treat pain, fever, and arthritis. A daily dose of aspirin can decrease the chance of heart attack or stroke. Aspirin works by blocking the special clotting cells in your blood called platelets. This can prevent dangerous blood clots from forming in the arteries of the heart, neck, and brain.<LineBreak>Aspirin can increase the chance of serious bleeding, even at low doses. Because of your medical condition, the danger to you from a possible heart attack or stroke is greater than the risk of bleeding. Unless specifically told to do so by your doctor, do not combine aspirin with other drugs that inhibit blood clotting, such as Coumadin (warfarin), Persantine (dipyridamole), or Plavix (clopidogrel). Aspirin should not be taken by pregnant women.</LineBreak><LineBreak>Take your aspirin dose once daily at the dose recommended by your doctor. A dose from 81 mg (a baby aspirin) to 325 mg (an adult aspirin) can be effective. To prevent stomach irritation, take the aspirin with food. Always follow the aspirin with a large glass or water.</LineBreak><LineBreak>Call your doctor if you have stomach pain, black or tarry stools, vomiting of blood, unusual bruising, or any prolonged bleeding while taking aspirin.</LineBreak>
</Instruction>
<Instruction title="Aspirina Diaria:" language="spanish">La aspirina ha sido usada por muchos años para tratar dolores, fiebres y artritis. Una dosis diaria de aspirina puede disminuir el riesgo de ataques al corazón o al cerebro. La aspirina funciona deteniendo el efecto de las células coagulantes de la sangre llamadas plaquetas. Esto suele prevenir el peligro de la formación de coágulos en las arterias del corazón, cuello y cerebro.<LineBreak>La aspirina puede aumentar el riesgo de hemorragias serias, aún en pequeñas dosis. Dada su condición médica, el peligro de un ataque al corazón o al cerebro es mayor que el riesgo de hemorragia. Salvo indicación del médico, no combinar aspirina con otras drogas inhibidoras de la coagulación, como Coumadin (warfarin), Persantine (dipyridamole) o Plavix (clopidogrel). Mujeres embarazadas no deben tomar aspirina..</LineBreak><LineBreak>Tomar la dosis diaria de aspirina recomendada por el médico. Una dosis de 81 mg (aspirina infantil) hasta 325 mg (dosis de adulto) suele ser efectiva. Para evitar irritación estomacal, tomarla con alimento y siempre con un vaso grande de agua.</LineBreak><LineBreak>Llame al médico si hay dolor de estómago, excremento ennegrecido, vómitos de sangre, moretones o cualquiera hemorragia prolongada mientras se está tomando aspirina.</LineBreak>
</Instruction>

</ES_DI>
<ES_DI id="XXXX" abbreviated_title="Clopidogrel (Plavix)" style="text">
<Index>
<Section>Treatment</Section>
<Menu>Cardio/Circ Tx</Menu>
</Index>
<Index>
<Section>Treatment</Section>
<Menu>Cardio/Circ Tx</Menu>
</Index>
<Instruction title="Clopidogrel (plavix):" language="english">Clopidogrel can decrease your chance of heart attack or stroke. It does this by blocking the action of the special clotting cells in your blood called platelets. This can prevent dangerous blood clots from forming in the arteries of the heart, neck, and brain.<LineBreak>Clopidogrel can increase the chance of serious bleeding. Because of your medical condition, the danger to you from a possible heart attack or stroke is greater than the risk of bleeding. Unless specifically told to do so by your doctor, do not combine clopidogrel with other drugs that inhibit blood clotting, such as Coumadin (warfarin), Persantine (dipyridamole), aspirin, or anti-inflammatory medicines such as ibuprofen or naproxen.</LineBreak><LineBreak>Clopidogrel is usually taken once daily. If you forget to take it at your usual time, it's OK to take it later.</LineBreak><LineBreak>Call your doctor if you have dizziness, weakness, changes in vision, chest pain, black or tarry stools, vomiting of blood, unusual bruising, or any prolonged bleeding. Women who are taking clopidogrel and become pregnant should contact their doctor immediately. If you're having surgery or dental work, be sure to tell the doctor or dentist that you're taking this medicine.</LineBreak>
</Instruction>
<Instruction title="Clopidogrel (plavix)" language="spanish">Clopidogrel puede disminuir el riesgo de ataque al corazón o al cerebro al parar el efecto de las células coagulantes de la sangre, llamadas plaquetas. Esto suele evitar el peligro de la formación de coágulos en las arterias del corazón, cuello y cerebro.<LineBreak>Clopidogrel puede aumentar el riesgo de hemorragias serias. Dada su condición médica, el peligro de ataque al corazón o al cerebro es mayor que el riesgo de hemorragia. Salvo indicación específica del médico, no combinar clopidogrel con otras drogas inhibidoras de la coagulación, como Coumadin (warfarin), Persantine (dipyridamole), aspirina o medicinas antiinflamatorias, como ibuprofen o naproxen.</LineBreak><LineBreak>Clopidogrel se suele tomar una vez al día; si se olvida de tomarlo a su hora, está bien tomarlo más tarde.</LineBreak><LineBreak>Llame al médico si aparecen mareos, debilidad, cambios en la visión, dolor de pecho, excremento ennegrecido, vómitos de sangre, moretones no usuales o cualquier hemorragia prolongada. Mujeres que queden embarazadas mientras toman clopidogrel, deberán consultar al médico de inmediato. Si se tiene cirugía o trabajo dental, avisar al médico o dentista que se está tomando este medicamento.</LineBreak>
</Instruction>
</ES_DI>
</ES_DI_collection>

to look like this-

<ES_DI_collection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ES_DI id="4476" abbreviated_title="Aspirin daily" style="text">
<Index>
<Section>Treatment</Section>
<Menu>Cardio/Circ Tx</Menu>
</Index>
<Instruction title="Daily Aspirin:" language="english">
<FlowDocument FontWeight="Normal" FontStretch="Normal" FontFamily="Arial" FontStyle="Normal" FontSize="12" AllowDrop="True" PagePadding="5,0,5,0" NumberSubstitution.CultureSource="User" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Paragraph xml:space="preserve">Aspirin has been used for many years to treat pain, fever, and arthritis. A daily dose of aspirin can decrease the chance of heart attack or stroke. Aspirin works by blocking the special clotting cells in your blood called platelets. This can prevent dangerous blood clots from forming in the arteries of the heart, neck, and brain. </Paragraph>
<Paragraph xml:space="preserve">Aspirin can increase the chance of serious bleeding, even at low doses. Because of your medical condition, the danger to you from a possible heart attack or stroke is greater than the risk of bleeding. Unless specifically told to do so by your doctor, do not combine aspirin with other drugs that inhibit blood clotting, such as Coumadin (warfarin), Persantine (dipyridamole), or Plavix (clopidogrel). Aspirin should not be taken by pregnant women. </Paragraph>
<Paragraph xml:space="preserve">Take your aspirin dose once daily at the dose recommended by your doctor. A dose from 81 mg (a baby aspirin) to 325 mg (an adult aspirin) can be effective. To prevent stomach irritation, take the aspirin with food. Always follow the aspirin with a large glass or water. </Paragraph>
<Paragraph xml:space="preserve">Call your doctor if you have stomach pain, black or tarry stools, vomiting of blood, unusual bruising, or any prolonged bleeding while taking aspirin. </Paragraph>
</FlowDocument>

</Instruction>
<Instruction title="Aspirina Diaria:" language="spanish">
<FlowDocument FontWeight="Normal" FontStretch="Normal" FontFamily="Arial" FontStyle="Normal" FontSize="12" AllowDrop="True" PagePadding="5,0,5,0" NumberSubstitution.CultureSource="User" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Paragraph>
<Span xml:space="preserve">La aspirina ha sido usada por muchos años para tratar dolores, fiebres y artritis. Una dosis diaria de aspirina puede disminuir el riesgo de ataques al corazón o al cerebro. La aspirina funciona deteniendo el efecto de las células coagulantes de la sangre llamadas plaquetas. Esto suele prevenir el peligro de la formación de coágulos en las arterias del corazón, cuello y cerebro. </Span>
</Paragraph>
<Paragraph Margin="0,6.67,0,6.67" FontFamily="Times New Roman" FontSize="16">
<Run FontSize="12" FontFamily="Arial">La aspirina puede aumentar el riesgo de hemorragias serias, aún en pequeñas dosis. Dada su condición médica, el peligro de un ataque al corazón o al cerebro es mayor que el riesgo de hemorragia. Salvo indicación del médico, no combinar aspirina con otras drogas inhibidoras de la coagulación, como Coumadin (warfarin), Persantine (dipyridamole) o Plavix (clopidogrel). Mujeres embarazadas no deben tomar aspirina.</Run>
</Paragraph>
<Paragraph Margin="0,6.67,0,6.67" FontFamily="Times New Roman" FontSize="16">
<Run FontSize="12" FontFamily="Arial">Tomar la dosis diaria de aspirina recomendada por el médico. Una dosis de 81 mg (aspirina infantil) hasta 325 mg (dosis de adulto) suele ser efectiva. Para evitar irritación estomacal, tomarla con alimento y siempre con un vaso grande de agua.</Run>
</Paragraph>
<Paragraph Margin="0,6.67,0,6.67" FontFamily="Times New Roman" FontSize="16">
<Run FontSize="12" FontFamily="Arial" xml:space="preserve">Llame al médico si hay dolor de estómago, excremento ennegrecido, vómitos de sangre, moretones o cualquiera hemorragia prolongada mientras se está tomando aspirina. </Run>
</Paragraph>
<Paragraph />
</FlowDocument>
</Instruction>
</ES_DI>

<ES_DI id="4477" abbreviated_title="Clopidogrel (Plavix)" style="text">
<Index>
<Section>Treatment</Section>
<Menu>Cardio/Circ Tx</Menu>
</Index>
<Index>
<Section>Treatment</Section>
<Menu>Cardio/Circ Tx</Menu>
</Index>
<Instruction title="Clopidogrel (plavix):" language="english">
<FlowDocument FontWeight="Normal" FontStretch="Normal" FontFamily="Arial" FontStyle="Normal" FontSize="12" AllowDrop="True" PagePadding="5,0,5,0" NumberSubstitution.CultureSource="User" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Paragraph xml:space="preserve">Clopidogrel can decrease your chance of heart attack or stroke. It does this by blocking the action of the special clotting cells in your blood called platelets. This can prevent dangerous blood clots from forming in the arteries of the heart, neck, and brain. </Paragraph>
<Paragraph Margin="0,6.67,0,6.67" FontFamily="Times New Roman" FontSize="16">
<Run FontSize="12" FontFamily="Arial" xml:space="preserve">Clopidogrel can increase the chance of serious bleeding. Because of your medical condition, the danger to you from a possible heart attack or stroke is greater than the risk of bleeding. Unless specifically told to do so by your doctor, do not combine clopidogrel with other drugs that inhibit blood clotting, such as Coumadin (warfarin), Persantine (dipyridamole), aspirin, or anti-inflammatory medicines such as ibuprofen or naproxen. </Run>
</Paragraph>
<Paragraph Margin="0,6.67,0,6.67" FontFamily="Times New Roman" FontSize="16">
<Run FontSize="12" FontFamily="Arial" xml:space="preserve">Clopidogrel is usually taken once daily. If you forget to take it at your usual time, it's OK to take it later. </Run>
</Paragraph>
<Paragraph Margin="0,6.67,0,6.67" FontFamily="Times New Roman" FontSize="16" xml:space="preserve">
<Run FontSize="12" FontFamily="Arial">Call your doctor if you have dizziness, weakness, changes in vision, chest pain, black or tarry stools, vomiting of blood, unusual bruising, or any prolonged bleeding. Women who are taking clopidogrel and become pregnant should contact their doctor immediately. If you're having surgery or dental work, be sure to tell the doctor or dentist that you're taking this medicine.</Run> </Paragraph>
<Paragraph />
</FlowDocument>
</Instruction>
<Instruction title="Clopidogrel (plavix)" language="spanish">
<FlowDocument FontWeight="Normal" FontStretch="Normal" FontFamily="Arial" FontStyle="Normal" FontSize="12" AllowDrop="True" PagePadding="5,0,5,0" NumberSubstitution.CultureSource="User" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Paragraph>
<Span xml:space="preserve">Clopidogrel puede disminuir el riesgo de ataque al corazón o al cerebro al parar el efecto de las células coagulantes de la sangre, llamadas plaquetas. Esto suele evitar el peligro de la formación de coágulos en las arterias del corazón, cuello y cerebro. </Span>
</Paragraph>
<Paragraph Margin="0,6.67,0,6.67" FontFamily="Times New Roman" FontSize="16">
<Run FontSize="12" FontFamily="Arial" xml:space="preserve">Clopidogrel puede aumentar el riesgo de hemorragias serias. Dada su condición médica, el peligro de ataque al corazón o al cerebro es mayor que el riesgo de hemorragia. Salvo indicación específica del médico, no combinar clopidogrel con otras drogas inhibidoras de la coagulación, como Coumadin (warfarin), Persantine (dipyridamole), aspirina o medicinas antiinflamatorias, como ibuprofen o naproxen. </Run>
</Paragraph>
<Paragraph Margin="0,6.67,0,6.67" FontFamily="Times New Roman" FontSize="16">
<Run FontSize="12" FontFamily="Arial" xml:space="preserve">Clopidogrel se suele tomar una vez al día; si se olvida de tomarlo a su hora, está bien tomarlo más tarde. </Run>
</Paragraph>
<Paragraph Margin="0,6.67,0,6.67" FontFamily="Times New Roman" FontSize="16">
<Run FontSize="12" FontFamily="Arial" xml:space="preserve">Llame al médico si aparecen mareos, debilidad, cambios en la visión, dolor de pecho, excremento ennegrecido, vómitos de sangre, moretones no usuales o cualquier hemorragia prolongada. Mujeres que queden embarazadas mientras toman clopidogrel, deberán consultar al médico de inmediato. Si se tiene cirugía o trabajo dental, avisar al médico o dentista que se está tomando este medicamento. </Run>
</Paragraph>
<Paragraph />
</FlowDocument>
</Instruction>
</ES_DI>
</ES_DI_collection>

The only difference in the two xmls is in the tags. I have tried all the xsl tags that can be used to transform the files and have reached a dead end. Please suggest some possible solution.

Thanks
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to decide what the transformation is supposed to do. The large glob of XML you posted just overloads my brain so I can't guess what elements are supposed to be transformed into what elements. So your first step is to explain what the transformation is supposed to do.
 
vanita maram
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Thanks for replying. I am sorry for the large blob. I want to include a <FlowDocument> tag right after an <instruction> tag.
Also I want the transformation to replace the tags <LineBreak> from One xml file to <Paragraph> tag in the transformed xml but contain the same information within the tags. If I can get some idea on how to just add and replcae xml tags then I can work on creating the rest of the xslt for replacing the other tags.


Thanks
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a better way of explaining the problem. Next, you need to get used to the fact that XML and XSLT work with elements and not tags. (In case you don't know the difference: an element consists of a start tag, optionally some contents, and and end tag. Except for an empty element.)

So, you want to replace each LineBreak element by a Paragraph element with the same contents. And if I understand it correctly, for each Instruction element you want to output a FlowDocument element which contains all the children of that Instruction element, inside an Instruction element with the same attributes.

When you are doing a transformation where the output document looks a lot like the input document, only with minor changes like that, then you should start with the identity transformation:If you apply this by itself then the output will be the same as the input. But you want the output to be different in some ways. So add templates that change the output. Here's one:So when the translator sees a LineBreak element, it will output a Paragraph element and then apply the rules to all of its attributes and children recursively. Since the rules usually say "copy me", you'll get a copy of the attributes and child nodes in the right place.

Try this for a start. Then write another template that expresses your other requirement. Then do whatever fixing up is needed after that.
 
vanita maram
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul

Thanks a ton for helping me with the xslt.
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is something similar to what i need but i do not want to change the element name its the elements value, what tag can i use for that?

Thanks,
Shane.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic